CH-6.2-Curve Fitting - Fall - 24-25
CH-6.2-Curve Fitting - Fall - 24-25
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.
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
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
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
3
Fall 2024-2025
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
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
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
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]
[Ref. Numerical Methods for engineers and Scientists – Amos Gilat, Vish Subramaniam,
Problem # 6.8, Page # 242]