0% found this document useful (0 votes)
27 views6 pages

CH-6.2-Curve Fitting - Fall - 24-25

Math 5

Uploaded by

raisulrifat25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

CH-6.2-Curve Fitting - Fall - 24-25

Math 5

Uploaded by

raisulrifat25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Fall 2024-2025

Numerical Methods for Science and Engineering


Lecture Note 6(2)
Curve Fitting

6.2.1 Introduction

The purpose of curve fitting is to find the parameters values of the model function that closely
match the data. The fitted curves can be used to estimate the values of one variable
corresponding to the specified values of the other variable. The method of least squares may be
one of the most systematic procedures to fit a curve through the given data points. In polynomial
interpolation we have considered the problem of finding polynomials of the least degree which
agree with the tabulated data. Spline interpolation is a form of polynomial interpolation where
the interpolant is a piecewise polynomial called spline. This means that between two points there
is a piecewise polynomial curve which joined smoothly to the neighboring curves. Cubic spline
has different important applications. One of the important applications is in Computer graphics.

6.2.2 Curve Fitting by Least Squares Method


The method of least squares may be one of the most systematic procedures to fit a curve through
given data points.
Consider the problem of fitting a set of n data points:
( x r , y r ) , r=1 . 2. 3 ,⋯, n

to a curve Y =f ( x ) whose values depends on m parameters 1 2 3


c ,c ,c ,⋯,c
m . The values of the
function at a point depend on the values of the parameter involved. In least square method we
c ,c ,c ,⋯,cm such that the sum of the squares of the
determine a set of values of the parameter 1 2 3
error
n
E ( c 1 , c2 , … , c m )=∑ [ f ( x i ,c 1 , c 2 , … , c m )− y i ]
2

i =1
is minimum.
The necessary conditions for E to have a minimum is that,
∂E
=0 , r =1, 2 , 3 ,⋯, m
∂c r
This condition gives a system of m equations, called normal equations, in m unknowns
c 1 ,c 2 ,c 3 ,⋯,cm .
If the parameters appear in the function in non-linear form, the normal equations become non-
linear and are difficult to solve. This difficulty may be avoided if f ( x ) is transformed to a form
which is linear in parameters.

n
∑ 1=n
Note that, i=1 .

1
Fall 2024-2025

Example 6.2.1
Given the following set of values of x and y:

x 1 2 3 4 5 6
y 1.553 1.638 0.685 0.428 0.679 0.164

A physicist wants to approximate the data using a periodic curve y=a+b sin x .
Estimate the parameters a and b to 2 decimal places using the least squares method.

Solution

Sum of the square deviation is:


6
E( a ,b )=∑ (a+b sin xi − y i )2
i=1
At minimum,
∂E ∂E
=0 =0
∂a and ∂b
These conditions give,
6
∑ 2 (a+b sin x i− y i ) 1=0
i=1
6
∑ 2 (a+b sin x i− y i ) sin x i=0
i=1
which can be rearranged as
a ∑ 1+b ∑ sin x i =∑ y i
a ∑ sin x i +b ∑ sin2 x i=∑ yi sin x i
The sum can be calculated as follows:
X y sin x sin2x y sin x
1 1.553 0.8415 0.7081 1.3068
2 1.638 0.9093 0.8268 1.4894
3 0.685 0.1411 0.0199 0.0967
4 -0.428 -0.7568 0.5727 0.3239
5 -0.679 -0.9589 0.9195 0.6511
6 0.164 -0.2794 0.0781 -0.0458
Sum 2.933 -0.1032 3.1251 3.8221

The normal equations are,


6 a 0.1032 b = 2.933
0.1032 a + 3.1251 b = 3.8221
By dividing each equation by the coefficient of a, we have
a 0.0172 b = 0.4888

2
Fall 2024-2025

a 30.282 b = 37.0359
Subtracting the equations
30.2648 b = 37.5247
Solving we have b=1. 2399≈1 .24
a=0 .5108≈0 . 51
Example 6.2.2
The height of a child is measured at different ages and listed below:

t (yrs) 3 6 9 12 15
H (ft ) 2.87 3.60 4.28 4.88 5.35

It is believed that height follows saturation growth model,


6.45
H= .
1+a 2 exp (−a3 t)
i. Use a suitable substitution to reduce the above relation to a linearized form in parameters.
ii. Use the least square method to find the normal equation of the above data.
iii. Estimate, to 2 decimal places, the values of a 2∧a3
iv. Estimate the height when the child becomes 20 years old.
v. Use MATLAB function a=lsqcurvefit (fun , a0 , xdata , ydata) to fit the general form like
a1
H= .
1+a 2 exp (−a3 t)
Solution
6.45
i. The curve H= is to be fitted to the given data.
1+a 2 exp (−a3 t)
6.45 −a t
The equation of the curve can be rewritten as −1=a2 e 3

H
Taking logarithm of both sides, we get ln (
6.45
H )
−1 =ln a2−a3t,
which can be written in the form,
Y = A +BX

where Y =ln ( 6.45


H
−1 ) , X =t , A=ln a ∧B=−a .
2 3

ii. Sum of the square deviation is:


5
E( A , B)=∑ ( A+BX i−Y i )2
i=1
∂E ∂E
=0 =0
At minimum, ∂A and ∂ B

3
Fall 2024-2025

These conditions give,


∑ 2 ( A +BX i −Y i ) 1=0
∑ 2 ( A +BX i −Y i ) X i=0
which can be rearranged as
A ∑ 1+B ∑ X i =∑ Y i
A ∑ X i + B ∑ X 2 =∑ X i Y i
i
The sum can be calculated in a tabular form as shown below:

2
n t H X Y XY X
1 3 2.87 3 0.221 0.663 9
2 6 3.60 6 -0.234 -1.402 36
3 9 4.28 9 -0.679 -6.113 81
4 12 4.88 12 -1.134 -13.609 144
5 15 5.35 15 -1.582 -23.727 225
Sum 45 -3.408 -44.187 495

Normal Equations
5 A + 45 B = -3.408
45 A + 495 B = -44.187

iii. Solutions: A + 9 B = -0.682


A + 11 B = -0.982
-2 B = 0.3

B = -0.150 a3 = 0.15
A = 0.668 a2 = 1.95

6.45
iv. The fitting curve is H= .
1+1.45 exp(−0.15 t)
From the equation of the curve, we get:
when t=20 then H =5.88.
v. >> xd=[3 6 9 12 15]; % state x-values
>> yd=[2.87 3.60 4.28 4.88 5.35]; % state y-values
Define fitting curve in terms of parameters as vector a
>> fun=@(a,xd) a(1)./(1+a(2).*exp(-a(3).*xd));
>> a0=[6,2,0.2]; % guess parameter values
% To fit the curve use MATLAB function lsqcurvefit with following syntax

4
Fall 2024-2025

>> a=lsqcurvefit(fun,a0,xd,yd)

Exercise 6.2

1. Find the least square line v=b+2 at to the following data (where b , a are constants)
t 0 2 4 5 7
v 6.7 9.2 11.5 15.6 19.2
7

2. Average price, P, of a certain type of second-hand car is believed to be related to its age,t
years, by an equation of the form
50
P= t
a+ b e 4
where a and b are constants. Data from a recent newspaper give the following average
price (in Taka) for used car of this type,

t (yrs) 2 4 6 8
P (lac) 20.50 17.25 14.50 11.75

(i) Estimate the values of a and b rounded to 3 significant figures.


(ii) Estimate the value of a car of this type that is 10 years old and the original new price.

3. A bowl of hot water is kept in a room at constant temperature of 250C. At 5 minutes interval
the temperature of the water is recorded and listed as given below.

t in minute 5 10 15 20 25
T in 0C 76.8 70.4 64.258.8 54.1
−kt
The law of cooling can be assumed to be of the form T =27+ ae .
(i) Find, to 2 significant figures, the best values of a and k .
(ii) Estimate the initial temperature.
(iii) Estimate the time, to the nearest minute, when the temperature of the water in the bowl
will be 500C.

4. The equation v=70−c e−kt can be used for calculating the speed of a moving car, where
c and k are constants.
The table below shows the speed of the car at various times,

t 4 8 12 16 20
v 23.21 28.52 33.07 36.96 40.29

(a) Estimate the values of c and k rounded to 2 significant figures.

5
Fall 2024-2025

(b) Find the time, to the nearest second, when the speed is 45 ms-1.

5. To measure g (the acceleration due to gravity), the following experiment is carried out. A
ball is dropped from the top of a tall building. As the object is falling down, the time t when
it passes sensors mounted on the building wall is recorded. The data measured in the
experiment is given in the table below.

h(m) 80 60 40 20 0
t (s ) 2.02 2.86 3.50 4.04 4.51

1 2
The position of the ball h as a function of time t is given by h=h0− g t .
2
Use linear regression to best fit the equation to the data and determine the
experimental value of h 0 and g.
[Ref. Numerical Methods for engineers and Scientists – Amos Gilat, Vish
Subramaniam, Problem # 6.7, Page # 242]

6. Water solubility in jet fuel, Ws, as a function of temperature, T, can be modeled by an


exponential function of the form W S=b emT . The following are values of water solubility
measured at different temperatures. Using linear regression, determine the constants m and
b that best fit the data. Use the equation to estimate the water solubility at a temperature of
100 C. Make a plot that shows the function and the data points.
0
T (¿ C)¿ −40 −20 0 20 40
W S (% wt .) 0.0012 0.002 0.0032 0.006 0.0118

[Ref. Numerical Methods for engineers and Scientists – Amos Gilat, Vish Subramaniam,
Problem # 6.8, Page # 242]

You might also like