# Curve fitting

• Nov 16th 2008, 10:00 AM
rainy cloud
Curve fitting
Hi everyone,

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?

RainyCloud
• Nov 16th 2008, 11:00 AM
CaptainBlack
Quote:

Originally Posted by rainy cloud
Hi everyone,

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?

RainyCloud

1. Adjust the weights in the objective so that the (0,0) point is weighted more heavily than the others.

2. Choose a family of fitting functions all of which pass through (0,0).

CB
• Nov 16th 2008, 02:44 PM
rainy cloud
Hi CaptainBlack,

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.

RainyCloud
• Nov 17th 2008, 09:06 PM
CaptainBlack
Quote:

Originally Posted by rainy cloud
Hi CaptainBlack,

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.

RainyCloud

You had better tell us what you know about curve fitting, and/or more background to your problem.

CB
• Nov 18th 2008, 04:55 PM
rainy cloud
Quote:

Originally Posted by CaptainBlack
You had better tell us what you know about curve fitting, and/or more background to your problem.

CB

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.
• Nov 23rd 2008, 01:02 AM
David24
Quote:

Originally Posted by rainy cloud
Hi everyone,

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?

RainyCloud

Hey mate,

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,

David
• Nov 23rd 2008, 01:33 AM
CaptainBlack
Quote:

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
• Nov 27th 2008, 05:21 AM
rainy cloud
Hi,

Thank you CaptainBlack and David24 for valuable help.

Best wishes,