Originally Posted by
rainy cloud What I understand about curve fitting, if I have some data points, we need to look for a function which fits these points provided the distance between the points and the curve of the function satisfy as small as they can.
I am really not sure about that I hope you correct my thought.
The following some data, how can I choose the best curve fitting for them
E=[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0]
C=[0.016123 0.015483 0.014737 0.013991 0.013190 0.012331 0.011478 0.010518 0.009398 0.008172 0.006781]
figure(1)
plot(E,C,'bx')
Thank you again.
You will not be able to get a decent fit to this data with a curve that goes through (0,0).
You will get a reasonably good fit from a quadratic, but the residuals show that this is not a statistically good fit. To do the job properly we need theory to tell us what the expected form of the curve is.
Below is some Euler code that does a quadratic fit, this should be easy to translate into Matlab and to modify the objective to any form you like.
Code:
>
>function Obj(v,E,C)
$ cpred=v(1)*E^2+v(2)*E+v(3);
$ err=(C-cpred)^2;
$ Err=sum(err);
$ return Err
$endfunction
>
>
>help nelder
nelder is a builtin function.
brent("f",a,d,eps) returns a minimum close to a. The function
goes away from a with step size d until it finds a good interval
to start a fast iteration. Additional parameters are passed to f.
nelder("f",v,d,eps) for multidimenional functions f(v), accepting
1xn vectors. d is the initial simplex size.
eps is the final accuracy.
Used by: neldermin, brentmin
>v=[0,0,0.012]
0 0 0.012
>Obj(v,E,C)
9.32421e-005
>xx=nelder("Obj",v,1,1e-12;E,C)
-0.00361415 0.0127619 0.00690228
>yy=xx(1)*E^2+xx(2)*E+xx(3);
>
>xplot(E,yy);
>hold on;color(5);plot(E,C);hold off;
>
CB