Вы находитесь на странице: 1из 8

Numerical Analysis

(4)

1
Lagrange Interpolation

Given a set of (n + 1) points,


(x0 , f ( x0 ) ), (x1, f ( x1 ) ), ...., (xn , f ( xn ) )

x0 … x, f(x0) … y

Find the polynomial of least order f n (x)

such that: f n ( xi ) = f ( xi ) for i = 0,1,..., n

Lagrange Interpolation Formula:


n
f n ( x) =  f ( xi )  i ( x)
i =0

(x − x )
n
 i ( x) =  (x − x )
j =0, j i
j

i j

𝑓 (𝑥 ) = 𝑙𝑛,𝑘 (𝑥 )𝑓(𝑥0 ) + 𝑙𝑛,𝑘 (𝑥 )𝑓 (𝑥1 )+ … + 𝑙𝑛,𝑛 (𝑥 )𝑓(𝑥𝑛 )

n : ‫بتحدد عدد االقواس الموجوده بالبسط او المقام‬


‫❖ لو عندك اول و آخر نقطه و عاوز تجيب النقطه اللي في المنتصف‬

𝑥(‫ )االخيره‬− 𝑥(‫)االولى‬


ℎ= , 𝑥(‫ )االخيره(𝑥 = )المطلوبه‬− ℎ
𝑛

2
Examples:

x0 = 1, x2 = 4, n = 3 find x1 ?
𝑥2 − 𝑥0
ℎ= , 𝑥1 = 𝑥2 − ℎ
𝑛
4 − 1
ℎ= = 1 , 𝑥1 = 4 − 1 = 3
3

x0 = 0, x1 = 3, n = 3 find x2 ?
𝑥1 − 𝑥0
ℎ= , 𝑥2 = 𝑥1 − ℎ
𝑛
3 − 2 1 1 8
ℎ= = , 𝑥2 = 3 − =
3 3 3 3

x1 = 2, x3 = 4, n = 2 find x2 ?
𝑥3 − 𝑥1
ℎ= , 𝑥2 = 𝑥3 − ℎ
𝑛
4 − 2
ℎ= = 1 , 𝑥2 = 4 − 1 = 3
2

Example:
x
With n = 2, f(x) = 2 , in the interval [0, 2] find f(x) using Lagrange
interpolation and find the value of x = √2

3
Solution
x0 = 0, x2 = 2, n = 2 then get x1
𝑥2 − 𝑥0
ℎ= , 𝑥1 = 𝑥2 − ℎ
𝑛
2 − 0
ℎ= = 1 , 𝑥1 = 2 − 1 = 3
2

f(X0) = 20 = 1, f(X1) = 21 = 2, f(X2) = 22 = 4


𝑓3 (𝑥 ) = 𝑙2,0 (𝑥 ) ∗ 1 + 𝑙2,1 (𝑥 ) ∗ 2 + 𝑙2,2 (𝑥 ) ∗ 4
(𝑥 − 𝑥1)(𝑥 − 𝑥2) (𝑥 − 1)(𝑥 − 2) (𝑥 − 1)(𝑥 − 2)
ℓ2,0 (𝑥) = = =
(𝑥0 − 𝑥1)(𝑥0 − 𝑥2) (0 − 1)(0 − 2) 2

(𝑥 − 𝑥0)(𝑥 − 𝑥2) (𝑥 − 0)(𝑥 − 2) 𝑥(𝑥 − 2)


ℓ2,1 (𝑥) = = =
(𝑥1 − 𝑥0)(𝑥1 − 𝑥2) (1 − 0)(1 − 2) −1

(𝑥 − 𝑥0)(𝑥 − 𝑥1) (𝑥 − 0)(𝑥 − 1) 𝑥(𝑥 − 1)


ℓ2,2 (𝑥) = = =
(𝑥2 − 𝑥0)(𝑥2 − 𝑥1) (2 − 0)(2 − 1) 2

(√2 − 1)(√2 − 2)
ℓ2,0 (√2) = = −0.12132
2
√2 (√2 − 2)
ℓ2,1 (√2) = = 0.82842
−1
(√2 − 1)(√2 − 2)
ℓ2,2 (√2) = = 0.29289
2

𝑓3 (𝑥 ) = −0.12132 ∗ 1 + 0.82842 ∗ 2 + 0.29289 ∗ 4 = 2.70708

4
Example:
Find f(4.5) with Lagrange interpolation when n=2 and
f(3)= -2, f(9) = 3, f(4) = 5
----------------
Example:
To find how much heat is required to bring a kettle of water to its
boiling point, you are asked to calculate the specific heat of water at
61C. The specific heat of water is given as a function of time in
Table

Determine the value of the specific heat at T = 61C using a first


order Lagrange polynomial.

5
Taylor's Series
Given data is f(X), X0

ℎ ′ ℎ2 ′′
𝑓 (𝑥 ) = 𝑓 (𝑥0 ) + 𝑓 (𝑥0 ) + 𝑓 (𝑥0 )
1! 2!
ℎ3 ′′′ ℎ𝑛 ′𝑛
+ 𝑓 (𝑥0 ) + ⋯ + 𝑓 (𝑥0 )
3! 𝑛!

h = X – X0

Example: f(x) = e x , determine Taylor's series to the second


order when x0 = 0, and also find f(2)
𝑓(𝑥0 ) = 𝑒0 = 1

𝑓′(𝑥0 ) = (𝑒𝑥 )′ = 𝑒0 = 1

𝑓′′(𝑥0 ) = (𝑒𝑥 )′′ = 𝑒0 = 1

h = x – x0 = x – 0 = x

ℎ ′ ℎ2 ′′ ‫لحد المشتقة التانيه النه‬


𝑓(𝑥) = 𝑓(𝑥0 ) + 𝑓 (𝑥0 ) + 𝑓 (𝑥0 ) ‫قال شتغل لحد ال‬
1! 2!
Second order
𝑥 𝑥2
𝑓 (𝑥 ) = 1 + (1) + (1)
1! 2!
2 22
𝑓 (𝑥 ) = 1 + (1) + (1) = 5
1! 2!

6
Notes on derivative:

7
Lagrange Example

Вам также может понравиться