I have a question regarding curve fitting to data.
My question is:
If I have some data points one of them is (0,0) and when I fit them to a curve, how can I control this fitting curve and force it to pass a definite point like (0,0).
Could anyone give help in this question?
Thank you in advance.
Thank you very much for your answer. Unfortunately, I haven't understood what you mean by adjusting the weights in the objective. Also, in 2., how can I choose a family of fitting functions pass through the (0,0) point.
Another point, how can I judge that a curve is the best fitting?
Thank you again.
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]
Thank you again.
here you wish to fit a curve f(x) over a set of data points say X such that the residual is minimised and the function passes through the origin,
i.e f(0) = 0
why not let f(x) = xg(x) and model to solve g(x),
i.e. lets say you wish to fit a polynomial to X that must pass through the origin
then f(x) = x( a0 + a1*x + .... + an*x^n) which for any solution of a0, a1, ... an will definately pass through the origin.
If we want to extend this so that at x = a, f(a) = A, then all that is required is a simple modification to the function as before
let f(x) = (x-a)g(x) + A
and solve for g(x), we observe that at x = a f(a) = A
hope this helps,
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.
CBCode:> >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; >