Professional Documents
Culture Documents
Matlab Assignment 4
Matlab Assignment 4
So f (3.5)= p3 (3.5)=0.430375
Problem 2:
a) We want to obtain the Lagrange linear interpolation in the following intervals:
[-3;-1] ; [-1;0] ; [0;3] ; [3;5]
For each interval, we can use the following formula to obtain the piecewise
polynomial:
( x −x) y 0+( x−x 0 ) y 1
p1 ( x)= 1
( x 1−x 0)
Therefore,
On [-3;-1], p1 ( x )=−2.5 x −5.5
On [-1;0], p1 ( x )=4 x +1
5
On [0;3], p1 ( x )= x+1
3
−3
On [3;5], p1 ( x )= x+10.5
2
p4 ( x)= y 0 +( x−x 0)[ x 0 , x 1 ]+( x −x0 )(x−x 1)[ x 0 , x 1 , x 2 ]+( x−x 0)(x−x 1)(x −x2 )[ x0 , x 1 , x 2 , x 3 ]+( x−x 0 )(
Plugging in the values from the table above and simplifying, we obtain the following:
p4 ( x )=0.05625 x 4 −0.40208 x 3−0.17292 x 2+ 4.28542 x+1
6 y 1− y 0
c) 2 M 0+ M 1=
h1( h1
−0
)
6 y n− y n−1
M n−1+ 2 M n=
hn (
0−
hn )
hi h +h h y − y y − y i−1
6 ( 3 i
)
M i−1+ i i +1 M + i+1 M i+1 = i +1 i − i
6 h i+1 hi
For i =1, 2 M 0+ 6 M 1 + M 2=39
For i =2, M 1+ 8 M 2 +3 M 3=−14
For i = 3, 3 M 2+10 M 3 +2 M 4=−19
^y =a0 +a1 x
n ∑ xy −∑ x ∑ y
a 1= 2
=0.5588
n ∑ x 2− ( ∑ x )
∑ x2 ∑ y−∑ x ∑ x y
a 0= 2
=1.353
n ∑ x 2−( ∑ x )
Therefore, the linear interpolation of the given data points, using the least squares
method, is given by ^y =1. 353+0. 5588 x.