diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/test/straight_line_fit/lin_vs_nonlin.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,52 @@
+mc
+
+a = 2;
+b = 3;
+x = -1:0.01:1;
+xa = ao(plist('dtype', 'cdata', 'yvals', x));
+  
+n = 1*randn(size(x));
+sn = 2;
+na = sn.*ao(plist('dtype', 'cdata', 'yvals', n));
+
+y0 = a.*(xa + b).^3;
+ya = y0 + na;
+
+%% linearisation
+
+
+% ylin = dyda.*da + dydb.*db + y0;
+
+da = 0.2;
+db = -0.3;
+ag = a+da;
+bg = b+db;
+y0 = ag.*(xa + bg).^3;
+
+dyda = (xa+bg).^3;
+dydb = ag.*(xa+bg).^2;
+
+tgtData = ya-y0;
+fitData = lscov(dyda, dydb, tgtData);
+
+dfit = fitData - tgtData;
+iplot(dfit)
+iplot(hist(dfit))
+
+params = find(fitData.procinfo, 'P')
+af = ag + params(1)
+bf = bg + params(2)
+
+errs = find(fitData.procinfo, 'STD');
+
+afe = 100*errs(1)./af
+bfe = 100*errs(2)./bf
+
+%% Non-linear fit
+
+xy = ao(plist('xvals', x, 'yvals', ya.y));
+pl = plist('Function', 'P(1).*(Xdata + P(2)).^3', 'P0', [ag bg]);
+nlfit = curvefit(xy, pl);
+
+
+