5.7.4 Cubic Spline Interpolation for Equally and Unequally Spaced Values According to the idea of draftsman spline, it is required that both dy dx and the curvature 2 2 d y dx are the
Trang 11 S(x i ) = f(x i ); i = 0, 1, 2, n
2 On each subinterval [x i–1 ,x i], 1≤ i≤ n, S(x) is a polynomial in n of degree at most n
3 S(x) and its (n –1) derivatives are continuous on [a, b].
4 S(x) is a polynomial of degree one for x < a and x > b.
The process of constructing such type of polynomial is called spline interpolation
5.7.4 Cubic Spline Interpolation for Equally and Unequally Spaced Values
According to the idea of draftsman spline, it is required that both dy
dx and the curvature
2 2
d y
dx are
the same for the pair of cubic that join at each point The cubic spline have possess the following properties:
1 S(x i ) = f i , i = 0, 1, 2, ,n.
2 The cubic and their first and second derivatives are continuous i.e., S(x), SI (x) and SII (x) and continuous on [a, b]
3 On each subintervals [x i–1 , x i] 1≤ i≤ n, S(x) is a third degree polynomial.
4 The third derivatives of the cubics usually have jumps discontinuities at the ducks or the junction points
Y
P0
f(x )1 P1
Ducks
f(x )2
P2
x0 x1 x2 xi xi + 1 xi + 2 xn – 1 xn X
f(x )i
f(xi + 1)
Pi
Pi + 1
Spline curve
f(xi + 2)
Pi + 2
Pn – 1 f(xn – 1)
f(x )n
Pn
FIG 5.4 Where x i = for i = 0, 1, 2 , n may or may not be equally spaced.
Let a cubic polynomial for the i th interval is
S(x i ) = a i (x – x i)3 + b i (x – x i)2 + c i (x – x i ) + d i (1)
Since this polynomial is valid for both the points x i and x i+1 therefore,
S(x i ) = a i (x i – x i)3 + b i (x i – x i)2 + c i (x i – x i ) + d i (2)
⇒ S(x i ) = d i
S(x i+1 ) = a i (x i+1 – x i)3 + b i (x i+1 – x i)2 + c i (x i+1 – x i ) + d i
⇒ S x( )i+1 = a h i i3+1 +b h i 2i+ 1+c h i i+l +d i (3)
where h i + 1 = x i + 1 – x i
Trang 2Now, Twice differentiate Equation (1) we get,
S’ (x i ) = 3a i (x – x i)2 + 2b i (x – x i ) + c i (4)
Now, Let P i = S’’ (x i) then equation (5) becomes
P i = 6a i (x – x i ) + 2b i
P i = 2b i
2
i i
P b
P i + 1 = 6a i (x i + 1 – x i ) + 2b i
P i + 1 = 6a i (x i+1 – x i ) + P i [using (6)]
P i + 1 = 6a i h i+1 + P i
a i = 1
1
6
i
h
+ +
−
(7)
Now substituting the values of d i , a i and b i from (2), (6) and (7) in (3)
( )i 1
1
1
1
i i
i
P
( )i 1
1
i
P h
P+ −P + + h + +c h+ +s x
( )i 1
i
S x + − + h + +c h+
( )i 1
6
i
h
S x = + P+ − +P P +c h+
2
1 1
3 6
i
h
+ +
−
1 1
2 6
i
h
+ +
−
Now, the slope at the point x i (because the curve has equal slope at the point [x i , S(x i)] hence from equation (4)
S’ (x i ) = 3a i (x i – x i)2 + 2b i (x i – x i ) + c i ⇒S x′( )i =c i (9)
c i = S’ = ( )1 ( ) 1
i
h
+
−
− P i+1+2P i (10)
But S’ (x i) for the last subinterval is,
S’ (x i ) = 3a i–1 h2
i + 2b i–1 h i + c i–1 .(11)
and after using a i–1 , b i–1 , and c i–1
−
+
Trang 3S’ (x i) = ( ) ( )1 2 1
6
i i
h h
For equation (9) and (10)
c i = 3a i–1 = h i2 + 2b i–1 h i + c i–1
On substituting the values of a i–1 , b i–1 , c i–1 and c i
1 1
2 2
+ +
1 1
2 2
S x S x
−
+ +
−
−
( ) ( ) ( ) ( )1 1 1 ( 1 ) 1
1
1
S x S x
+
−
for i = 1, 2, n – 1
⇒ ( ) ( 1) ( ) ( ) ( )1
1
+
Now for equally spaced argument i.e., h i = h Equation (13) becomes
[ 1 1] ( 1) ( ) ( 1)
6
4
h P+ + P +P− = S x+ − S x +S x−
or P i+1 + 4P i + P i – 1 = 62
h [S(x i + 1 ) – 2S (x i ) + S(x i–1)] (14)
while the S(x) for equally spaced becomes.
1)
h
+ ( 1) ( ) 2
1
6
h
(15)
Equation (15) gives cubic spline interpolation while equation (14) gives the condition for P i Remarks:
(1) IfP0 = P = 0n ; it is called free boundary conditions and the spline curve for this condition
is called the natural spline because the splines are assumed to take their natural straight line shape outside the interval of approximation
(2) IfP0 = P , Pn n+1 =P1; f0= , f n f1= f n+1, h1=h n+1then spline is called periodic splines (3) For a non-periodic spline we use
0 '( ) , ( ) n
f a = f′ ′f b = f′
⇒ 2 + 0 1 = 6 i 0 0
i
− − ′
⇒ 1 1
6
−
Trang 4Example 1 Obtain cubic spline for every subinterval, given in the tubular form.
( )
f x 1 2 33 244 With the end conditions M 0 = 0 = M 3
Sol Here, we have equal spaced intervals as h1 = h2 = h3 = 1, hence the condition for M i
becomes
⇒ M0 +4M1 +M2 =6f x( )2 −2 f x( )1 + f x( )0
⇒ M1+4M2+ M3 =6f x( )3 −2f x( )2 + f x( )1
Now, after substituting the values of f(x i ) and M0 = 0 = M 3 we get
M1= −24and M2 =276
t0 = 1 t1 = 2 t2 = 33 t3 = 244 Now, the corresponding cubic spline can be obtained by having
1
, 1, 2, 3
h
Now, for i = 1 (the interval is [0, 1]), f(x) = – 4x3 + 5x + 1
Similarly, for [1, 2], f(x) = 50x3 – 162x2 + 167x – 53 and for [2, 3],
f(x) = – 46x3 + 414x2 – 985x + 715.
Example 2: Find the cube splines for following data:
( )
f x : 1 2 5 11 with the end condition M0 = 0 = M 3 and also calculate f (2.5)and f’(2.5).
Sol Here intervals are equally spaced with difference 1 and n = 3 Now, the condition for
M iis
⇒ M0 +4M1 +M2 =6f x( )0 −2f x( )1 + f x( )2
Trang 5⇒ M1+4M2 +M3 =6f x( )1 −2 f x( )2 + f x( )3
but M0 = 0 M3 then it becomes
4M1+M2 =12and M1=4M2 =18
M1 = 2 and M2 = 4 Now, the corresponding cubic spline can be obtained by having
( ) ( )3 ( )3 ( )
1
Now, for i = 1 (the interval is [0, 1])
f(x) = 1( 3 )
2 3
3 x + x+
Similarly, for [1, 2] f(x) =1
3 (x3 + 2x + 3) and for [2, 3], f(x) =
1
3 (−2x3+18x2 −34x+27)
Now, f(2.5) = 7.66 and f ’ (2.5) = 6.16
Example 3 Obtain the cubic spline for the following data:
( )
f x : 2 −6 −8 2 Sol Take initial conditions M0 = 0 = M 3 for i = 1, 2 n
h2 [M i–1 + 4M i + M i+1 ] = 6 [f i+1 – 2f i + f i–1]
Here, h = 1;
∴ M0 +4M1 +M2 =6(f2 −2f1 + f0) for0≤ ≤x 1
M1+4M2 +M3 =6(f3−2f2 + f1)for1≤ ≤x 2
Using initial conditions, we get
M1 = 4.8, M2 = 16.8
Hence for 0≤ x≤ 1 spline is given by
1
6 −x M + x− M + −x f −M + x− f −M
= 0.8x3−8.8x+2
Hence for 1≤ x≤ 2 spline is given by
S(x) = 2x 3 – 3 6x2 – 5.2x + 0.8
Similarly, for 2≤ x≤ 3
S(x) = –2.8x3 + 25.2x2 – 62.8x + 39.2 Ans
Trang 6Example 4 Estimate the function value f at x = 7 using cubic splines from the following data: Given
P 2 = P 0 = 0.
i i
Sol h1 = x1 – x0 = 9 – 4 = 5
h2 = x2 – x1 = 16 – 9 = 7
1 2
+
⇒ 1 1
70
P = − = – 0.0143
Since, n = 3 therefore, there are two cubic splines given by
S1 (x) = x0≤ x≤ x1
S2 (x) = x1≤ x≤ x2
( ) { ( )3 ( )3 }
1
+ − − + − −
For i = 1
S(x) = { ( )3 ( )3 } ( ) 12
h
1
1
6
h
h
+ − −
27 0.0143 3 25 0.0024
S( )7 =2.64862 Ans
PROBLEM SET 5.5
1 Using the Chebyshev polynomials T n (x), obtain the least square approximation of degree eleven for f(x) = cos–1 x. ( ) 0 ( ) 1 ( ) 3( ) 5 ( )
Ans.
9
2 Find the linear least-squares polynomial approximation to the function f(x) = 5 + x 2 on the
29 6 6
3 Find the quadratic least squares polynomial approximation to the function f(x) = x3/2 on the
105
Trang 74 Using the Chebyshev polynomials T n (x), obtain the least squares approximation of second degree for f(x) = 4x3 + 2x2 + 5x – 2 on the interval [1, 1].
[Ans f(x) = – T0 (x) + 8T1 (x) + T2 (x)]
5 Find the best lower-order approximation to the cubic 9x3 + 7x2 , –1 ≤ x ≤ 1
7 , max.error = in [-1, 1]
6 Economize the series e x2 = 1 + x2 +
x + x + x + x + x + on the interval [–1, 1]
allowing for a tolerance of 0.05 [Ans ex2 = 1.0075 + 0.869x2 + 0.8229x4]
7 Economize the series x +
x + x + x on the interval [–1, 1], allowing for a tolerance
8 Find a uniform polynomial approximation of degree 1 to (2x – 1)3 on the interval [0, 1] so that the maximum norm of the error function is minimized, using Lanczos economization Also calculate the norm of the error function
Hint: Put x = t+21, linear approximation = 3( )
4 x− maximum error = 1
4
9 Find the lowest order polynomial which approximates the function f(x) =1 – x + x 2 – x 3 + x4, 0 ≤ x ≤ 1 with an error less than 0.1 ( ) 160 2 160 131
10 Obtain an approximation in the sense of the principle of least squares in the form of a
polynomial of second degree to the function f(x) = 2
1
1 x+ in the range –1≤ x≤ 1.
[Ans P (x) = 34 (2π– 5) +15
4 (3 – p) x
2]
11 Find the polynomial of second degree, which is the best approximation in maximum norm
to x on the point set { 4 1 }
0, , , 1, 0
2
12 Find a polynomial P(x) of degree as low as possible such that 2 ( )
1
[Ans 1.0075 + 0.8698x2 + 0.82292x4]
13 Prove that x 2 = 0( ) 2( )
1
2T x +T x ·
14 Express T0 (x) + 2T1 (x) + T2 (x) as polynomials in x. [Ans 2x + 2x2]
15 Economize the series f(x) = 1 – 2 3
2 8 16
16 Economize the series cos x = 1 – 2 4 6
2 24 720
17 Prove that T n (x) is a polynomial in x of degree n
18 Find the best lower order approximation to the cubic 5x3 + 4x2 in the closed interval
4x]
Trang 819 Find cubic spline for the following data:
( )
1 2 5 11
x
f x with end conditions P0 = 0 = P3 and also calculate f(2.5), f’(2.5).
20 Estimate the function value f at x = 7 using cubic splines from the following data:
4 9 16
i i
i x
21 Fit the following points by the cubic spline:
( )
: 1 2 3 4 : 1 5 11 8
x
f x
By using the conditions M0 = 0 = M3 Hence find f(1.5) and f ’(2)
15
Ans
15
f x = − x − x − x+ ≤ ≤x
38 456 1741 1980 3 4 15
22 Find the cubic spline corresponding to the interval [2, 3] which means the following representation:
( )
: 30 15 32 18 25
x
f x
with the end condition M 1 = 0 = M5 and also compute f(2.5), f’(3)
16
23 Fit the following points by Cubic spline and obtain y(1.5):
x
3 x−1 +4x−12 ( )1.5 5.625
24 Obtain cubic spline approximation valid in the interval [3, 4],
Given that
3 10 29 65
x y Under the natural spline conditions M(1) = 8 = M(4).
15
Ans
,
GGG
Trang 9CHAPTER 6
Numerical Differentiation
and Integration
6.1 INTRODUCTION
The differentiation and integration are losely linked processes which are actually inversely related
For example, if the given function y(t) represents an objects position as a function of time, its
differentiation provides its velocity,
=
( ) d ( )
dt
On the other hand, if we are provided with velocity v(t) as a function of time, its integration
denotes its position
0 ( ) ( )
t
There are so many methods available to find the derivative and definite integration of a function But when we have a complicated function or a function given in tabular form, they we use numerical methods In the present chapter, we shall be concerned with the problem of numerical differentiation and integration
6.2 NUMERICAL DIFFERENTIATION
The method of obtaining the derivatives of a function using a numerical technique is known as numerical differentiation There are essentially two situations where numerical differentiation is required
They are:
1 The function values are known but the function is unknown, such functions are called tabulated function
2 The function to be differentiated is complicated and, therefore, it is difficult to differentiate The choice of the formula is the same as discussed for interpolation if the derivative at a point near the beginning of a set of values given by a table is required then we use Newton forward formula, and if the same is required at a point near the end of the set of given tabular
294
Trang 10values, then we use Newton’s backward interpolation formula The central difference formula (Bessel’s and Stirling’s) used to calculate value for points near the middle of the set of given
tabular values If the values of x are not equally spaced, we use Newton’s divided difference
interpolation formula or Lagrange’s interpolation formula to get the required value of the derivative
6.2.1 Derivation Using Newton’s Forward Interpolation Formula
Newton’s forward interpolation is given by
y=y + ∆ +u y − ∆ y + − − ∆ y
(1)
u h
Differentiating equation (1) with respect to u, we get
= ∆ + ∆2 + 2 ∆3
Now dy
dy
du·
du
dx =
1
h
dy du
⋅
Therefore,
Asx=x u0, =0, therefore, putting u = 0 in (3), we get
=
0
x x
dy
Differentiating equation (3) again w.r.t ‘x’, we get
= = ×
2 2
1
dx
= ∆ + − ∆( ) + − + ∆ −
2
2
12
Putting u = 0 in (4), we get
=
= ∆ − ∆ + ∆ −
0
2
12
x x
d y
Similarly,
=
= ∆ − ∆ +
0
3
2
x x
d y