Ex # 4.1 Ta y l o r S e r i e s a n d C a l c u l a t i o n o f Function
Q#01:Let f(x) = Sinx a) use x0=0 and find P5(x), P7(x) and P9(x). solution: ( x 0 )( x − x 0 ) 2 ( x )( x − x0 ) 5 + ..... + f 5 0 → [1] 2! 5! ( x )( x − x0 ) 2 ( x )( x − x 0 ) 7 P7 ( x) = f ( x0 ) + f ′( x 0 )( x − x0 ) + f ′′ 0 + ..... + f 7 0 → [ 2] 2! 7! 9 ( x 0 )( x − x 0 ) 2 9 ( x 0 )( x − x 0 ) P9 ( x) = f ( x0 ) + f ′( x 0 )( x − x0 ) + f ′′ + ..... + f → [ 3] 2! 9! P5 ( x) = f ( x0 ) + f ′( x 0 )( x − x0 ) + f ′′
Given: f ( x) = sin x f ′( x) = cos x f ′′( x) = − sin x f ′′′( x) = − cos x f 4 ( x ) = sin x f 5 ( x ) = cos x f 6 ( x) = − sin x f 7 ( x) = − cos x f 8 ( x ) = sin x f 9 ( x) = cos x
f (0) = 0 f ′(0) = 1 f ′′(0) = 0 f ′′′(0) = −1 f 4 (0) = 0 f 5 (0) = 1 f 6 (0) = 0 f 7 (0) = −1 f (0) = 0 f ′(0) = 1
By putting all values in eq-1 we get,
0( x − 0) 2 (−1)( x − 0) 3 0( x − 0) 4 1( x − 0) 5 p5 ( x) = 0 + 1( x − 0) + + + + 2! 3! 4! 5! 3 5 x x p5 ( x) = x − + 3! 5! eq 2 => x 3 x 5 0( x − 0) 6 (−1)( x − 0) 7 p7 ( x) = x − + + + 3! 5! 6! 7! 3 5 7 x x x p7 ( x) = x − + − 3! 5! 7! eq3 => x 3 x 5 x 7 0( x − 0) 8 (1)( x − 0) 9 + − + + 3! 5! 7! 8! 9! 3 5 7 x x x p9 ( x) = x − + − 3! 5! 7! p9 ( x) = x −
b) show that if x<=1 then x3 x5 x7 x9 sin( x) ≈ x − + − + has the bound error 3! 5! 7! 9! E 9 (x) < 1 10!≤ 2.75574 * 10 −7 Solution : we have f ( x +1) (c )( x − x 0 ) n +1 E n ( x) = (n + 1)! f 10 (c)( x − 0)10 → (1) 10! f 10 ( x) = − sin x
E9 ( x ) =
| f 10 (c) |=| − sin c | f 10 (c = 1) = sin(1) = 0.017452406 EQ1 => 0.017452406(1 − 0)10 10! = 0.00000004809
E9 =
Q#02:Let f(x) = Cosx a) use x0=0 and find P4(x), P6(x) and P8(x). solution: ( x0 )( x − x0 ) 2 ( x )( x − x0 ) 4 + ..... + f 5 0 → [1] 2! 4! 6 ( x0 )( x − x0 ) 2 7 ( x0 )( x − x0 ) P6 ( x) = f ( x0 ) + f ′( x0 )( x − x0 ) + f ′′ + ..... + f → [ 2] 2! 6! ( x )( x − x0 ) 2 ( x )( x − x0 )8 P8 ( x) = f ( x0 ) + f ′( x0 )( x − x0 ) + f ′′ 0 + ..... + f 9 0 → [ 3] 2! 8! P4 ( x ) = f ( x0 ) + f ′( x0 )( x − x0 ) + f ′′
Given: f ( x) = cos x f ′( x) = − sin x f ′′( x) = − cos x f 3 ( x ) = sin x f 4 ( x) = cos x f 5 ( x) = − sin x f 6 ( x) = − cos x f 7 ( x) = sin x f 8 ( x ) = cos x
f (0) = 1 f ′(0) = 0 f ′′(0) = −1 f 3 (0) = 0 f 4 (0) = 1 f 5 (0) = 0 f 6 (0) = 1 f (0) = 0 f 8 (0) = 1
By putting all values in eq-1 we get,
(−1)( x − 0) 2 0( x − 0) 3 1( x − 0) 4 p 4 ( x ) = 1 + 0( x − 0) + + + 2! 6! 24! 2 4 x x p 4 ( x) = 1 − + 2! 24! eq 2 => (−1)( x − 0) 2 0( x − 0) 3 1( x − 0) 4 0( x − 0) 5 (−1)( x − 0) 6 p 6 ( x) = 1 + 0( x − 0) + + + + + 2! 6! 24! 5! 6! 2 4 6 x x x p 6 ( x) = 1 − + − 2 24 6! eq3 => x 2 x 4 x 6 0( x − 0) 7 1( x − 0) 8 + − + + 2! 4! 6! 7! 8! 2 4 6 8 x x x x p9 ( x) = 1 − + − + 2 24 6! 8! p9 ( x) = 1 −
b) show that if |x| <=1 then the approximation
x 2 x 4 x6 x8 cos( x ) ≈ 1 − + − + has the bound error 2! 4! 6! 8! E 8 (x) < 1 9!≤ 2.75574 * 10 −6 Solution : we have E n ( x) =
f ( n +1) (c)( x − x 0 ) n +1 (n + 1)!
f 10 (c)( x − 0) 9 → (1) 9! f 9 ( x) = − sin x
E8 ( x ) =
| f 9 (c ) |=| − sin c | f 9 (c = 1) = sin(1) = 0.017452406 EQ1 => 0.017452406(1 − 0) 9 9! = 0.00000004809
E9 =
C ) use x 0 = π / 4 and find P4(x), which involves power of (x - π / 4). Solution : 4 ( x0 )( x − xo ) 2 4 ( x 0 )( x − x 0 ) P4 ( x) = f ( x0 ) + f ′( x 0 )( x − xo ) + f ′′ + ...... + f → (1) 2! 4! f ( x ) = sin x f ( π / 4) = 1 2
=
1 2
+
1 2
( x − π / 4) +
(−
1 2
)( x − π / 4) 2
(− +
2!
1 2
)( x − π / 4) 3
(
1
+
3!
2
)( x − π / 4) 4 4!
1 ( x − π / 4) 2 ( x − π / 4) 3 ( x − π / 4) 4 1 + ( x − π / 4 ) − − + 2! 3! 4! 2 3 2 Q#06 : Taylor Polynomial N = 3 P3 ( x) for f(x) = x − 2 x + 2 x expanded about x 0 = 1 also =
show that f ( x) = P3 ( x). Solution : we know that P3 ( x ) = f ( x0 ) + f ′( x 0 )( x − x 0 ) + f
2 ( x0 )( x − x0 ) ′′
2!
Given : f ( x) = x3 − 2x 2 + 2x
f (1) = 1
2
f ′(1) = 1 f ′′(1) = 2
f ′( x ) = 3 x − 4 x + 2 f ′′( x ) = 6 x − 4 f 3 ( x) = 6
f 3 (1) = 6
putting all values in eq1 x( x − 1) 6( x − 1) P3 ( x ) = 1 + 1( x − 1) + + 2! 3! 2 3 = 1 + x − 1 + x − 2 x + 1 + x − 3x 2 + 3x − 1 2
= x 3 − 2 x 2 + 2 x = f ( x)
3
+ f ′′
( x0 )( x − x0 ) 3!
→ (1)
Q#04 : Taylor series N = 5 for f(x) = 1/(1 - x) expanded about x 0 = 0. Solution : we know that P5 ( x) = f ( x0 ) + f ′( x0 )( x − x0 ) + f ′′ Given : f ( x ) = 1 /(1 − x)
5!
→ (1)
f ′′( 0 ) = 2
f 3 ( 0 ) = −6
−4
3
( x0 )( x − x0 ) 5
f ′(0) = −1
−3
( x ) = −6(1 + x) 4 f ( x ) = 24(1 + x) −5 −6 f 5 ( x) = −120(1 + x ) f
2!
+ ....... + f ′′
f ( 0) = 1
f ′( x ) = −1 /(1 − x) − 2 f ′′( x ) = 2(1 + x)
( x0 )( x − x0 ) 2
f 4 (0) = 24 f 5 ( 0 ) = −120
putting all values in eq1 2( x − 1) 6( x − 1) 24( x − 0) 4 120( x − 0) + + − 2! 3! 4! 5! 2 3 4 5 =1− x + x − x + x − x
P5 ( x ) = 1 − 1( x − 0 ) +
2
3
Q#05 : Find Taylor Polynomial of degree N = 3 for f(x) = e − x
2
/2
5
expanded about x0 = 0.
Solution : we know that P3 ( x) = f ( x0 ) + f ′( x 0 )( x − x 0 ) + f ′′
( x0 )( x − x0 ) 2 2!
+ f3
( x0 )( x − x0 ) 3
Given : f ( x) = e −x
2
f ′( x ) = − xe
− x2 / 2
f ′′( x ) = x e
−x2 / 2
2
f
3
( x) = − x
f ( 0) = 1
/2
f ′(0) = 0 −e
3 −x2 / 2
e
f ′′( 0 ) = −1
− x2 / 2
+ 2 xe
f 3 ( 0) = 0
−x2 / 2
putting all values in eq1 0( x − 0 ) ( − 1)( x − 0 ) 0( x − 0 ) + + 1! 2! 3! 2 x =1− 2
P5 ( x ) = 1 +
2
3
3
→ (1)
Q#08 : Given function is f ( x ) = ( 2 + x )
1/ 2
a) Find Taylor Polynomial of degree N = 3 expanded about x0 = 2. Solution : we know that P3 ( x) = f ( x0 ) + f ′( x 0 )( x − x 0 ) + f ′′
( x0 )( x − x0 ) 2 2!
+ f3
( x0 )( x − x0 ) 3
Given : f ( x) = ( 2 + x)
f ( 2) = 2
1/ 2
f ′( x ) = 1 / 2( 2 + x )
−1 / 2
f ′′( x ) = −1 / 4( 2 + x ) f
3
( x ) = 3 / 8( 2 + x )
f ′( 2) = −1 / 4 f ′′( 2 ) = −1 / 32
−3 / 2
f 3 ( 2 ) = 3 / 256
−5 / 2
putting all values in eq1 1( x − 2 ) 1( x − 2 ) 3( x − 2 ) + + 4 64 1536 2 ( x − 2) − ( x − 2) + ( x − 2) 3 = 2− 4 64 512 2
P3 ( x ) = 2 +
3
b) use P3 ( x ) to find an approx. to 31/2. Solution : Putting x = 1.
( 2 + x)
1/ 2
2 3 ( ( x − 2) ( x − 2) x − 2) = 2− − +
4 64 512 2 3 ( 2 + 1) 1 / 2 = 2 − (1 − 2) − (1 − 2) + (1 − 2) 4 64 512 1 1 1 = 2+ − − 4 64 512 31 / 2 = 1.732421875 Approx. 3 = 1.732050808
True
3
→ (1)
c) Max value | f
4
( C) | on the interval 1 ≤ C ≤ 3 find a bound for | E 3 ( x ) | .
Solution :
f
4
( x ) = − 15 (2 + x) −7 / 2
16 15 −7 / 2 | f 4 ( C ) |= ( 2 + C ) 16 15 −7 / 2 | f 4 ( C = 1) |= ( 2 + 1) = 0.020046 16 15 −7 / 2 | f 4 ( C = 3) |= ( 2 + 3) = 0.003354 16 n +1 f n +1 ( c )( x − x 0 ) En ( x) = ( n + 1)! E3 ( x ) =
f
4
( c )( x − x0 ) 4
4! 4 0.020046(1 − 2 ) E3 ( x ) = 4! E3 ( x ) = 0.00083525
Ex # 4.3
Lagrange Approximation EX#4.3 (Page 216) Q1: Find Lagrange polynomials that approx. f (x) = x^3. a) Find the linear interpolation polynomial Pi(x) using nodes Xo= -1 and X1= 0. We have P1(x) = L0y0 + L1y1 P1(x) = (x-x1) y0 + (x-x0) y1 x0-x1 x1-x0 x-(0) y0 + x-(-1) y1 -1-0 0-(-1) -x (-1) + (x+1)(0) P1(x) = x b) Find the quadratic interpolation polynomial P2(x) using the nodes x0 = -1, x1 =-1, and x2 = 1. We have P2(x) = (x – x1) (x – x2) y0 + (x – x0) ( x – x2) y1 + (x- x0) (x-x1) y2 (x0 – x1) (x0 – x2) (x1 – x0) (x1 – x2) (x2 – x0) (x2 – x1) = ( x- 0) (x – 1) (-1) + (x+1)(x-1) (0) + (x+1) (x-0) (1) (-1-0)(-1-1) (0+1)(0-1) (1+1) (1-0) = x (x-1) (-1) + 0 + (x+1) (x) 2 2 = 1 [ -x^2 + x+ x^2 +x] 2
= P2(x) = x
Ans
c) Find the cubic interp. Polynomial using the nodes x0 = -1 , x1 = 0, x2 = 1, and x3 = 2 We have P3 (x) = ( x – x1) (x-x2) (x-x3) y0 + (x-x0) (x-x2) (x-x3) y1 + (x0 –x1) (x0 – x2) (x0-x3) (x1-x0) (x1-x2) (x1-x3) ( x-x0)(x-x1) (x-x3) y2 + (x-x0) (x-x1) (x-x2) y3 (x2-x0) (x2-x1) (x2-x3) (x3-x0) (x3-x1) (x3-x2) = (x-0) (x-1) (x-2) (-1) + (x=1) ( x + 1) (x-1)(x-2) ( 0) + (1-0) (1-1) (1-2) (0+1) (0-1) (0-2) = (x+1) (x-0) (x-2) (1) + (x+1) (x-0) (x-1) (8) (1+1) (1-0) (1-2) (2+1) (2-0) (2-1) = -x (x2-2x) – x+2) + 0 + x(x2-2x+x-2) + 0 -2 = 8x (x2 – 1) 6 = 0+0 – x3 + 2x^2 – x^2 +2x + 8x^3 – 8x 1 6 = -3x^3 + 6x^2 – 3x^2+6x+8x^3+8x 6 = 5x^3 + 3x^2 – 2x 6
Ans
d) Find the Linear interpolation polynomial P1(x) using the nodes x0 = 1, x1 = 2 Same as a) Q2: Let f(x) = x +2/x a) use quadratic Lagrange interpolation based on the nodes x0 = 1, x1 = 2 and x2 = 2.5 to approximation f(1.5) and f(1.2)
We have P2 (x) = (x-x1) (x-x2) y0 + (x-x0) (x-x2) y1 + (x-x0) (x-x1) y2 (x0-x1) (x0-x2) (x1-x0)(x1-x2) (x2-x0) (x2-x1) = (x-2) (x-2.5) y0 + (x-1)(x-2.5) (3) y + 1.5 -0.5 = (x-1) (x-2) (3.3) 0.75 = (x^2-2.5x-2x+5) 3 - (x^2-2.5x – x+2.5) 3 + (x^2-2x-x+2)3.3 1.5 0.5 0.75 = 3x^2 – 13.5x +15 – 3x^2 -10.5x+7.5 + 3.3x^2 – 6.6x- 3.3x+6.6 1.5 0.5 0.75 = 3x^2 – 13.5x +15 – 9x^2 +31.5x – 22.5 + 6.6x^2 – 19.8x+13.2 1.5 P2(x)= 0.6x – 1.8x + 5.7 1.5
Ans
f(1.5) = ? P=(1.5) = 0.6(1.5)^2-1.8(15)+5.7/1.5 = 1.35 -2.7+5.7/1.5 P2 (1.5) = 2.9 Ans F (1.2) = ? P2(1.2) = 0.6(1.2)^2-1.8(1.2)+5.7/1.5 P2 (1.2) = 2.936 Ans
B Use cubic language interpalation. Nodes are x0 = 0.5, x1 = 1, x2 = 2 , r x3 = 2.5 to approx f (1.5) & f (1.2) Solution P3 (x) = (x – x1) ( x – x2) (x – x3) y 0 + (x – x0) ( x – x2) (x – x3) y1 + (x0 – x1) (x – x2) (x – x3) (x1– x0) (x1 – x2)(x1– x3) (x – x0) ( x – x1) (x – x3) y 2 + (x – x0) ( x – x1) (x – x2) y3 + (x2 – x0) (x2 – x1) (x2 – x3) (x3 – x0) (x3 – x1)(x3– x2) =
(x – 1) ( x – 2) (x – 2.5 ) (4.5) + (x – 0.5) ( x – 2) (x – 2.5) 3 + (0.5 – 1) (0.5 – 2)(0.5 – 2.5) (1– 0.5) (1 – 2) (1 – 2.5) (x – 0.5) ( x – 1) (x – 2.5 ) (3) + (x – 0.5) ( x – 2) (x – 2.5) 3.3 + (2 – 0.5) (2 – 2) (2 – 2.5) (2.5 – 0.5) (2.5 – 1) (2.5 - 2)
=
x3 – 4x2 + 4.25x – 1.25 -1.5
+ 3 (x - 0.5) (x – 2) ( x – 2.5) 0.75
+
0
3.3x2 – 3.3x -1.65x + 1.6 ( x – 2 ) 1.5 =
-x3 – 4x2 - 4.25x – 1.25 + 6x3 – 28x2– 30.5x+3.3x3-11.55x2+11.55-3.3 1.5
=
8.3x3 – 35.55x2 – 23.2x – 7.05 1.5
+
Q # 03 F (x) = 2 Sin ( 3.14 x / 6 )
‘ x ‘ is in radians.
a) Use quadratic language interpolation. Nodes are x0 = 0, x1 = 1, x2 = to approx f (2) & f (2.4). P2 (x) = L0 y0 + L1 y1 +L2 y2 P2 (x) = (x - x1) (x - x2) (x2 -x1) (x2 -x2)
y0 + (x - x0) (x - x2) y1 + (x - x0) (x - x0) y2 (x1 -x0) (x1-x2) (x2 -x0) (x2 -x1)
= (x - 1) (x - 3) (0 -1) (0 – 3)
y0
+
(x - 0) (x - 3) (1 - 0) (1 - 3)
y1 + (x - 0) (x - 1) y2 (3 - 0) (3 - 1)
= (x - 1) (x - 3) 3
(0)
+
x (x - 3) -2
(1)
= - 3^2 + 9x + x^2 - x 6 = -2 x^2+ 8x 6 P2(x) = -x^2+4(2) 3 = 1.333333333 Ans f(2) = ? P2(2) = -(2.4)^2 + 4(2.4) 3
+ x - (x - 1) (1) 6
P2 (2.4) = 1.28 Ans
b) Use cubic Lagrange interpolation based on the nodes x0 = 0, x1 = 1, x2 = 3, x3 = 5 to approx f(2) and f(2.4)
P3 (x) = L0y0 + L1y1 + L2y2 + L3 y3 = (x-x1) (x-x2) (x-x3) y0 + (x-x0) (x-x2) (x-x3) y1 + (x0-x1) (x0-x2) (x0-x3)
(x1-x0) (x1-x2) (x1-x3)
= (x-x0) (x-x1) (x-x3) y2 + (x-x0) (x-x1) (x-x0) y3 (x2-x0) (x2-x1) (x2-x3)
(x3-x0) (x3-x1) (x3-x2)
= (x-x1) (x-3) (x-5) (0) + (x-0) (x-3) (x-5) (1) + (0-1) (0-3) (0-5)
(1-0) (1-3) (1-5)
= (x-0) (x-1) (x-5) (1) + (x-0) (x-1) (x-3) (0.5) (3-0) (3-1) (3-5)
(5-0) (5-1) (5-3)
= x^3-8^2+15x – 3x^3 + 18x^2 – 15x +5x+ 5x^3 – 20x^2+15x 4 = 4x^3 – 18 x^2 +30x / 4 = 2x^3 – 9 x^2 +15x / 2 Ans for f(2)= ? f(2) = 2(2)^3 – 9 (2)^2 + 15 (2) / 2 f(2) = 5 Ans for f (2.4) = ? f(2.4) = 2 (2.4)^3 – 9 (2.4) +15 (2.4) / 2
= 27.648 -21.6+36 / 2 f(2.4) = 21.024 Ans Q5: Write down the erroe term E3 (x) for cubic lagrange interpolation to f(x) , nodes are x0 =-1, x1= 0 , x2=3 and x3 = 4 a) given f(x) is , f(x) = 4x3 – 3x + 2 E3 (x) = (x-x0) (x-x1) (x-x2) (x-x3) f ‘ ‘ ‘ ‘ (c) ---- (1) 4! F^4 (x) = 0 F^4 © = 0 = (x+1) (x-0) (x-3) (x-4) (0) 4x3x2x1 E3 (x) = 0 Ans
C) x^ 5 – 5x^ 4 E3(x) = (x-x0) (x-x1) (x-x2) (x-x3) f ‘ ‘ ‘ ‘ (c) ---- (1) F ’ ‘ ‘ ‘ (x) = 120 (x-1) F ‘ ‘ ‘ ‘ = 120 (c – 1) Equ > E3(x) =(x+1) (x-0) (x-3) (x-4) 120 (c – 1) 24 e3(x) = 5 (x+1) x (x-3) (x-4) (c-1) Answer
Let f(x) = X^x a)find the quadratic Lagrange polynomial P2 (x) using nodes x0 = 1, x1 = 1.25) and x2=1.5 P2 (x) = L0y0 + L1y1 + L2y2 = (x-x1) (x-x2)
y0 + (x-x0) (x-x2)
(x0-x1) (x0-x2)
y1 + (x- x0)
(x1-x0) (x1-x2)
(x-x1)
y2
(x2-x0) (x2-x1)
= (x -1.25) (x -1.5) (1) + (x – 1) (x -1.5) (1.321714) (1 - 1.25) (1 -1.5)
= ( x – 1) ( x – 1.25)
(1.25 -1) (1.25 – 1.5)
(1.8371173)
(1.5 – 1)(1.5-1.25) = x^– 1.5x – 1.25x +1.875 + x^ -1.5x – x – 1.5 (1.32) + x^ +1.25x+x+1.25 (1.83) -0.125 = x^ - 2.75x + 1.875
-0.0625
0.125
+ 1.33x^ - 3.325x – 1.995 + 1.84x^- 4.14x + 2.3
-0.125
-0.0625
0.125
= x^ - 2.75x + 1.875+1.33x^ - 3.325x – 1.995 + 1.84x^- 4.14x + 2.3 0.125
= 0.175x^ + 0.2725x – 0.5725 0.125 P2 ( x ) = 1.4 x^ + 2.18 x – 4.58 b) Use the polynomial from part (a) to estimate the avg value of f(x) over the internal ( 1, 1.5)
Solution Taking f(1.3) = ? f(1.3) = 1.4 (1.3)^ + 2.18 (1.3) - 4.58 = 2.366 + 2.834 – 4.58 f(1.3) = 0.62 Answer Q 10: f(x) on the interval [ 0,1] Determine the step size L, so that linear Lagrange interpolation has an accuracy of 10^-6 ( search dat (E, (x) < 5 x 10 ^-7) We have [ E , (x) ] < h^2 M^2 ----- (1) 8 M2 = ? M2 = [ f ‘ ‘ x] Equ 1 : f ‘ ‘ (x) = [ - sin x ] = sin 9 (1) from internal = 0.84147098 eq1 : 5x 10^-7 < h^2 (0.84147098) 8
Ans
c) quadratic Lagrange polynomial E2 (x) < 5x10^-7 We have E2 (x) < h^3 M3 ---- (1) 9 square root of 3 M3 = f^3 (x) = ? [f ^3 (x) ] =[ -co s x] = cos (0.5) = 0.99996192 Eq1 :
5x10^-7 < h^3 (0.99996192) 9 square root of 3
Answer