Professional Documents
Culture Documents
Curve Fitting
One of the oldest and most applied problems in mathematics is the problem of
constructing an approximation to a given function from a discrete set of data pairs. The
fundamental two dimensional curve-fitting problem from a discrete set of (x, y) data pairs
(x1, y1) through (xn, yn) is to predict the value of y when the value of x is specified. There
are a number of ways to do this curve-fitting, depending on the kind of data available and
the specific conditions placed on the resulting curve.
In this chapter, we consider methods which do not account for random errors in
the x and y values as in the least squares approximation. The data will be treated as
accurate and determine a curve that passes through the data points exactly. The most
general and powerful tools for curve-fitting is approximation theory and the simpler but
less robust technique is interpolation. Classical methods for fitting curves involve
polynomial models.
[5.1a]
𝑛
𝑦(𝑥) = ∑ 𝐿𝑗 𝑦𝑗
𝑗=1
The popularity of Langrange formula is well known because it is easy to code and
the data are not required to be specified with x in ascending or descending order.
Although the computation of y is simple, but for large values of n, the method is still not
efficient. The Langrange’s form is useful for interpolating tables and for deriving formulas
for numerical differentiation and integration.
Example 5.1. For the data pairs (x1, y1), (x2, y2) (x3, y3), fit a curve using the Langrange
interpolation.
Solution:
𝑦(𝑥) = 𝐿1 𝑦1 + 𝐿2 𝑦2 + 𝐿3 𝑦3
when j = 1, i = 2, 3; j = 2, i = 1, 3; j = 3, i = 1,2
𝑥 − 𝑥2 𝑥 − 𝑥3 𝑥 − 𝑥1 𝑥 − 𝑥3 𝑥 − 𝑥1 𝑥 − 𝑥2
𝑦(𝑥) = ( )( ) 𝑦1 + ( )( ) 𝑦2 + ( )( )𝑦
𝑥1 − 𝑥2 𝑥1 − 𝑥3 𝑥2 − 𝑥1 𝑥2 − 𝑥3 𝑥3 − 𝑥1 𝑥3 − 𝑥2 3
Example 5.2 Compute ln 9.2 when ln 9.0 = 2.1972, ln 9.5 = 2.2513, ln 11.0 = 2.3979
Solution:
𝑦(𝑥) = ln(𝑥)
𝑥 − 9.5 𝑥 − 11.0 𝑥 − 9.0 𝑥 − 11.0
𝑦(𝑥) = ( )( ) 2.1972 + ( )( ) 2.2513
9.0 − 9.5 9.0 − 11.0 9.5 − 9.0 9.5 − 11.0
𝑥 − 9.0 𝑥 − 9.5
+( )( ) 2.3979
11.0 − 9.0 11.0 − 9.5
𝑦(𝑥) = 2.1972(𝑥 2 − 20.5𝑥 + 104.5) − 3.0017(𝑥 2 − 20𝑥 + 99) + 0.7993(𝑥 2 − 18.5𝑥
+ 85.5)
𝑦(𝑥) = −0.0052𝑥 2 + 0.2050𝑥 + 0.756
hence,
ln(9.2) = 𝑦(9.2) = 2.2192
Example 5.3 The elapsed time t(sec) for a car to accelerate to a speed v(mph) from an
initial speed of 30 mph is described by the data in Table 5.1. Fit a polynomial to describe
the function using Newton’s form. Estimate the time for the car to accelerate to a speed
of 50 mph.
Table 5.1 Car’s speed versus time to accelerate
i 1 2 3 4
v(mph) 30 40 55 70
t(sec) 0.0 1.6 4.8 8.9
j = 2;
3.2 1.6
𝑡[𝑣2 ,𝑣3 ]−𝑡[𝑣1 ,𝑣2 ] − 1.6
15 10
𝑡1,2 = 𝑡[𝑣1 , 𝑣2 , 𝑣3 ] = = 55−30 = 750
𝑣3 −𝑣1
4.1 3.2
𝑡[𝑣3 ,𝑣4 ]−𝑡[𝑣2 ,𝑣3 ] − 0.9
15 15
𝑡2,2 = 𝑡[𝑣2 , 𝑣3 , 𝑣4 ] = = =
𝑣4 −𝑣2 70−40 450
j = 3;
0.9 1.6
𝑡[𝑣2 ,𝑣3 ,𝑣4 ]−𝑡[𝑣1 ,𝑣2 ,𝑣3 ] − 0.3
450 750
𝑡1,3 = 𝑡[𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 ] = = = − 9000
𝑣4 −𝑣1 70−30
Recall that the Newton interpolation involved two stages: the computation of
coefficient and the evaluation of the polynomial. Neville’s algorithm is a method that
requires about the same effort as the first stage of the Newton interpolation. It is used
with n pairs of data (x1, y1) through (xn, yn) to obtain y(x) directly for a given value of x.
The aim of the method is to evaluate a polynomial of degree (n-1) by a process
that is similar to the computation of the coefficients of the Newton polynomial. However,
the quantities fk,j in Figure 5.1 are now
𝑓𝑘,0 = 𝑦𝑘
[(𝑥 − 𝑥𝑘+𝑗 )𝑓𝑘,𝑗−1 − (𝑥 − 𝑥𝑘 )𝑓𝑘+1,𝑗−1 ]
𝑓𝑘,𝑗 =
𝑥𝑘 − 𝑥𝑘+𝑗
𝑗 = 1, 2, ⋯ , 𝑛 − 1
𝑘 = 1, 2, ⋯ , 𝑛 − 𝑗
The interpolated value y(x) for a given x is the last computed quantity y(x) = f1, n-1.
𝑎𝑡 𝑗 = 2;
[(𝑣 − 𝑣3 )𝑡1,1 − (𝑣 − 𝑣1 )𝑡2,1 ] (50 − 55)3.2 − (50 − 30)(56/15) 272
𝑡1,2 = = =
𝑣1 − 𝑣3 30 − 55 75
56 103
[(𝑣 − 𝑣4 )𝑡2,1 − (𝑣 − 𝑣2 )𝑡3,1 ] (50 − 70)(15) − (50 − 40)( 30 ) 109
𝑡2,2 = = =
𝑣2 − 𝑣4 40 − 70 30
𝑎𝑡 𝑗 = 3;
272 109
[(𝑣 − 𝑣4 )𝑡1,2 − (𝑣 − 𝑣1 )𝑡2,2 ] (50 − 70)( 75 ) − (50 − 30)( 30 )
𝑡1,3 = = = 3.63
𝑣3 − 𝑣4 30 − 70
Therefore,
𝑡(50) = 3.63 𝑠𝑒𝑐
5.2 SPLINE INTERPOLATION
This suggests that the interpolation might be unsatisfactory if we insist on increasing the
order of the polynomial. However, if we keep the order of the polynomial fixed and use it
over different intervals, with the length of the interval decreasing, then interpolation can
be very accurate. This type of curve fitting is known as spline interpolation. The spline
interpolation is applied to n ordered pairs of data. We seek (n-1) curves that connects
points 1 and 2, points 2 and 3, … , and points (n-1) and n as shown in Figure 5.3.
y
A(x k 1 x )
2
( y" ) k B( x x k ) 2 ( y" ) k 1
C1x C2 eq.3
6
At (xk,yk), A =1, B = 0 and at (xk+1,yk+1),A = 0, B = 1. Determine C1 and C2 and substitute the
values into equation 2 and 3
y Ay k By k 1
(A 3
A)(y" ) k (B3 B)(y" ) k 1 ( x k 1 x k )
eq.4
6
Example 5.5 Use natural spline to estimate the elapsed time t(sec) for a car to accelerate
From 30 mph to 50 mph
i 1 2 3 4
v 30 40 55 70
t 0 1.6 4.8 8.9
Solution:
d2t
let t"
dv 2
(25 3 )(t" ) 2 (15 6 )(t" )3 3.215 1.610
(15 6 )(t" ) 2 (30 3 )(t" )3 4.115 3.215
t 1.6 3 2( 4.8) 3 (8 27)(t" ) 2 (10 27)(t" )3 152 6
t 3.612 sec