how to use nlinfit
15 views (last 30 days)
Show older comments
I have a data Y like this:
0
0.1386
0.1875
0.2315
0.2315
0.2125
0.2062
0.2125
0.2062
0.2572
0.2188
0.2572
0.2315
0.3164
1.0670
1.7491
1.6116
1.1873
0.7250
0.5233
0.3641
0.3031
0.3097
0.3164
0.3367
0.4131
0.3435
0.3367
0.3164
0.3367
0.2898
0.2636
0.3299
0.3031
0.2767
0.3164
0.2898
0.3367
0.3232
0.3031
Data X:
0
1.4300
2.8600
4.2900
5.7200
7.1500
8.5800
10.0100
11.4400
12.8700
14.3000
15.7300
17.1600
18.5900
20.0200
21.4500
22.8800
24.3100
25.7400
27.1700
28.6000
30.0300
31.4600
32.8900
34.3200
35.7500
37.1800
38.6100
40.0400
41.4700
42.9000
44.3300
45.7600
47.1900
48.6200
50.0500
51.4800
52.9100
54.3400
55.7700
This is a curve, which I need to approximate by a function
modelfun = @(k,t)(((1.*k(1))./(k(1)-k(2))).*(-exp(-k(1).*t)+exp(-k(2).*t)));
So, I need to estimate the parameters k(1) and k(2). Here I'm using nlinfit function
beta = nlinfit(X,Y,modelfun,beta0)
with
beta0 = [0.1 0.2].
When I get the parameters, I want to get the opposite - generate data similar to Y, but when I do this by
Y = modelfun(beta,X)
I get the wrong results and I do not know why?????
1 Comment
Star Strider
on 14 Mar 2014
You seem to be doing everything correctly. Plotting your data, it is obvious that your modelfun does not describe it.
Y has a peak at X = 23.45. Either you need to revise your model to accommodate the peak, or if the peak is noise, collect new data and fit your function to it.
Only you can determine what is most appropriate.
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!