You are on page 1of 11

Curve Fitting by Function Approximation

Curve fitting: the process of finding the equation of the curve which best fits the
given values and is most suitable for predicting the unknown values.
Function approximation: The goal would be to come up with an approximating
functional form using a finite set of data points.
Way to solve:
1.Method of Group averages
2.Method of moments
Method of group of averages
Algorithm :

1. Line to be fitted for the data is y=ax+b; where a and b needs to be calculated.
2. Divide the set of data into two groups.
3. Compute the averages of x’s and y’s in two groups.
4. Substitute it to the line y=ax+b then solve for the value of a and b.
Example .
Fit a straight line 𝑦 = 𝑎 𝑥 2 + 𝑏𝑥 + 𝑐 to the ff. data.

X 0 2 4 6 8 10

y 6 9 12 14 17 20
Let 𝑦
= 𝑎 𝑥 + 𝑏𝑥 + 𝑐
2

First we have to convert it into standard form; y=ax+b form

1. take any point in the data , let say (2,9) as a point on the curve
y=ax2+bx+c eq.(1)

9=a(22) +b(2)+c
9=4a+2b+c eq. (2)
2.Subtracting eq.(1) to eq.(2) , we get ;
y-9 /x-2 = a(x+2) + b
3. Which is in the form of Y = aX + b eq(3)
(where Y=y-9/x-2 and X = x+2)
Divide the given data into two groups:

x y X=x+2 Y=y-9/x-2
0 6 2 1.5
2 9 4 0
4 12 6 1.5
total 12 3

x y X=x+2 Y=y-9/x-2
6 14 8 1.25
8 17 10 1.34
10 20 12 1.375
total 30 3.965

The averages of x’s and y’s in two group are:


X1 =12/3=4 X2 =30/3=10
Y1=3/3=1 Y2 =3.965/3=1.321
Substituting these averages in Y=aX+b eq.(3), we have:

4a+b=1
10a+b=1.321

Solving for a and b, we get;

a=0.0535 , b=-0.786

To solve for c, substitute a and b to eq.(2)

9=4a+2b+c
9=4(0.0535) + 2(0.786) + c
c=7.214

So the required best fit for the data is y=0.0535 x2 + 0.786 x + 7.214

check: let x= 6;
y=o.o535 x2+ 0.786 x+ 7.214
y=o.o535 (6)2+ 0.786 (6)+ 7.214
y=13.856
Method of moments
Algorithm :

1. Let (x1 ,y1), (x2 ,y2), (x3 , y3),...(xn- yn-1) be n set of points or observation such that x
is equally spaced. i.e x2- x1=x3- x2
2. Let h=xn- xn-1.
3. Solve for the moment of y or (𝜇);
𝜇𝑚 = ℎ σ 𝑥 𝑚−1 𝑦
4. Let y=f(x) is a given curve.
5. Solve for the moment of calculated value or (γ);

𝑥𝑛 −2
𝛾𝑚 = ‫׬‬ ℎ 𝑥 𝑚−1 𝑓 𝑥 𝑑𝑥
𝑥1 −
2
6. Assume; 𝜇𝑚 = 𝛾𝑚

𝑥𝑛 − 2
ℎ σ 𝑥 𝑚−1 𝑦 =‫׬‬ ℎ 𝑥 𝑚−1 𝑓 𝑥 𝑑𝑥
𝑥1 −2
example:
fit a straight line to the ff. data . X 1 2 3 4
y 16 19 23 26

Let the equation of the straight line: y=a+bx

h=xn- xn-1 ( let say n=2)


h=2-1
h=1

For moment of y; 𝜇𝑚 = ℎ σ 𝑥 𝑚−1 𝑦

The first moment : 𝜇1 = 1 σ 𝑥 1−1 𝑦


𝜇1 = 84
The second moment: 𝜇2 = 1 σ 𝑥 2−1 𝑦
𝜇2 = 227
Let y=f(x)
For the moment of the calculated value (γ);

𝑥𝑛 −
2
𝛾𝑚 = න 𝑥 𝑚−1 𝑓 𝑥 𝑑𝑥

𝑥1 −2
The first moment :
1
𝑥4 −
𝛾1 = ‫׬‬ 1
2
𝑥 1−1 𝑓 𝑥 𝑑𝑥
𝑥1 −
2
𝛾1 = 4𝑎 + 10𝑏 eq.1
The second moment:
1
𝑥4 −2
𝛾2 = න 𝑥 2−1 𝑓 𝑥 𝑑𝑥
1
𝑥1 −2
𝛾𝑚 = 10𝑎 + 30.33𝑏 eq.2

Assume 𝜇𝑚 = 𝛾𝑚
4a + 10b = 84
10a + 33.33b = 227
By solving; a=13.2 and b=3.19
y= a + bx
y= 13.02 + 3.19 x answer

You might also like