Mercurial > hg > ltpda
comparison m-toolbox/test/straight_line_fit/lin_vs_nonlin.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 mc | |
2 | |
3 a = 2; | |
4 b = 3; | |
5 x = -1:0.01:1; | |
6 xa = ao(plist('dtype', 'cdata', 'yvals', x)); | |
7 | |
8 n = 1*randn(size(x)); | |
9 sn = 2; | |
10 na = sn.*ao(plist('dtype', 'cdata', 'yvals', n)); | |
11 | |
12 y0 = a.*(xa + b).^3; | |
13 ya = y0 + na; | |
14 | |
15 %% linearisation | |
16 | |
17 | |
18 % ylin = dyda.*da + dydb.*db + y0; | |
19 | |
20 da = 0.2; | |
21 db = -0.3; | |
22 ag = a+da; | |
23 bg = b+db; | |
24 y0 = ag.*(xa + bg).^3; | |
25 | |
26 dyda = (xa+bg).^3; | |
27 dydb = ag.*(xa+bg).^2; | |
28 | |
29 tgtData = ya-y0; | |
30 fitData = lscov(dyda, dydb, tgtData); | |
31 | |
32 dfit = fitData - tgtData; | |
33 iplot(dfit) | |
34 iplot(hist(dfit)) | |
35 | |
36 params = find(fitData.procinfo, 'P') | |
37 af = ag + params(1) | |
38 bf = bg + params(2) | |
39 | |
40 errs = find(fitData.procinfo, 'STD'); | |
41 | |
42 afe = 100*errs(1)./af | |
43 bfe = 100*errs(2)./bf | |
44 | |
45 %% Non-linear fit | |
46 | |
47 xy = ao(plist('xvals', x, 'yvals', ya.y)); | |
48 pl = plist('Function', 'P(1).*(Xdata + P(2)).^3', 'P0', [ag bg]); | |
49 nlfit = curvefit(xy, pl); | |
50 | |
51 | |
52 |