How can I find these values using polyfit command?
4 views (last 30 days)
Show older comments
Altin Guberi
on 30 May 2015
Commented: Altin Guberi
on 6 Jun 2015
Alright , so i have the values of t time respectively first colum and R radioactive decay which corresponds to second colum (look below ) . The formula of radioactive decay is R=R0 * e^(-λt). Now I wanted to know if there is any way to find the values of R0 and λ for each case by using command polyfit ?
Does anybody have an idea how can I do this?
Thank you & Have a great day.
Values : 10 312
11 328
12 311
13 290
14 283
15 285
16 255
17 291
18 271
19 272
20 253
21 255
22 263
23 246
24 264
25 213
26 261
27 241
28 228
29 242
30 215
31 192
32 206
33 182
34 188
35 197
36 195
37 180
38 210
39 176
40 183
41 199
42 159
43 171
44 166
45 145
46 181
47 177
48 137
49 149
50 185
51 148
52 149
53 142
54 150
55 140
56 149
57 123
58 112
59 118
60 145
61 146
62 118
63 113
64 120
65 126
66 120
67 125
68 114
69 114
70 117
71 103
72 102
73 96
74 97
75 102
76 117
77 114
78 88
79 94
80 101
81 93
82 113
83 74
84 78
85 81
86 102
87 94
88 93
89 81
90 64
91 88
92 81
93 96
94 72
95 82
96 81
97 71
98 71
0 Comments
Accepted Answer
Walter Roberson
on 30 May 2015
Edited: Walter Roberson
on 30 May 2015
When R=R0 * e^(-λt) then log( R) = log(R0 * e^(-λt)) so log( R) = log(R0) + log(e^(-λt)) so log( R) = log(R0) - λ*t . This gives us a simple linear fit,
P = polyfit(t, log( R), 1);
and then λ = P(1) and log(R0) is P(2)
4 Comments
Walter Roberson
on 30 May 2015
You asked to fit a single decaying exponential line through the series of points. The result will be the two coefficients needed to express that single decaying exponential. Just like if you have a set of 100 points and you ask to fit a straight line through them, the result would just be the slope and the intercept, two values, not two values for each of the 100 points.
Perhaps what you are looking for is a list of times and projected values. Perhaps you are looking for a plot.
Values = [10 312
11 328
12 311
13 290
14 283
15 285
16 255
17 291
18 271
19 272
20 253
21 255
22 263
23 246
24 264
25 213
26 261
27 241
28 228
29 242
30 215
31 192
32 206
33 182
34 188
35 197
36 195
37 180
38 210
39 176
40 183
41 199
42 159
43 171
44 166
45 145
46 181
47 177
48 137
49 149
50 185
51 148
52 149
53 142
54 150
55 140
56 149
57 123
58 112
59 118
60 145
61 146
62 118
63 113
64 120
65 126
66 120
67 125
68 114
69 114
70 117
71 103
72 102
73 96
74 97
75 102
76 117
77 114
78 88
79 94
80 101
81 93
82 113
83 74
84 78
85 81
86 102
87 94
88 93
89 81
90 64
91 88
92 81
93 96
94 72
95 82
96 81
97 71
98 71];
p = polyfit(Values(:,1), log(Values(:,2)), 1);
predicted = exp(p(2)) * exp(p(1)*Values(:,1));
plot(Values(:,1), Values(:,2), 'r*', Values(:,1), predicted, 'b-');
Or if you prefer, you can use
predicted = exp(polyval(p,Values(:,1));
Perhaps you would like to see error estimates:
t = Values(:,1);
R = Values(:,2);
[p, S, mu] = polyfit(t, log(R), 1);
[y, delta] = polyval(p, t, S, mu);
predictedR = exp(y);
plot(t, R, 'k*', t, predictedR, 'b-', t, exp(y-delta),'r-', t, exp(y+delta), 'r-');
The portion inside the red lines should contain 50% of the actual samples.
To go beyond this to get least-squared-fit of the actual data rather than least-squared fit of the log data, then you would need the Curve Fitting Toolbox, or the Stats Toolbox and use nlinfit()
But as for getting a pair of fitting values for each datapoint: NO. Not unless you are using a very different fit such as Piecewise Cubic Spline.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!