Docsity

Lagrange Interpolation and Neville's Method: Approximating Functions with Polynomials, Assignments of Mathematics

Toggle sidebar
bg1
Math 151A Homework #4 – due Friday 10/24
1Construct a Lagrange interpolating polynomial approximation to the function f(x) =
2x2−2 using the points
a. x0= 0, x1= 1
P1(x) = (x−1)
(0 −1) (−2) + (x−0)
(1 −0) (0)
= 2x−2
b. x0= 0, x1= 1, x2= 2
P2(x) = (x−1)(x−2)
(0 −1)(0 −2) (−2) + L2,1(0) + (x−0)(x−1)
(2 −0)(2 −1) (6)
= (x2−3x+ 2) + 3(x2−x)
= 2x2+ 2
c. x0=−1, x1= 0, x2= 1, x3= 2
P3(x) = (x+ 1)(x−1)(x−2)
(0 + 1)(0 −1)(0 −2) (−2) + (x+ 1)(x−0)(x−1)
(2 + 1)(2 −0)(2 −1) (6)
=−(x3−2x2−x+ 2) + x3−x
= 2x2−2
2Approximate √2 using Neville’s method with f(x) = √xand x0= 0, x1= 1,x2= 4,x3= 9
and x4= 16.
Nevilles method looks like this:
function Q = neville(X,Q,x)
n = length(X);
for i = 2:n
for j = 2:i
Q(i,j) = (x-X(i-j+1))*Q(i,j-1) - (x-X(i))*Q(i-1,j-1);
Q(i,j) = Q(i,j)/(X(i)-X(i-j+1));
endfor
endfor
endfunction
Pay attention to the indices, because octave/matlab counts from 1.
This generates:
octave:1> X=[0 1 4 9 16];
octave:2> Q=[0 1 2 3 4;zeros(4,1),zeros(4)]’
Q =
pf2

Partial preview of the text

Download Lagrange Interpolation and Neville's Method: Approximating Functions with Polynomials and more Assignments Mathematics in PDF only on Docsity!

Math 151A Homework #4 – due Friday 10/

1 Construct a Lagrange interpolating polynomial approximation to the function f (x) = 2 x^2 − 2 using the points

a. x 0 = 0, x 1 = 1

P 1 (x) =

(x − 1) (0 − 1)

(x − 0) (1 − 0)

= 2 x − 2

b. x 0 = 0, x 1 = 1, x 2 = 2

P 2 (x) =

(x − 1)(x − 2) (0 − 1)(0 − 2)

(−2) + L 2 , 1 (0) +

(x − 0)(x − 1) (2 − 0)(2 − 1)

= (x^2 − 3 x + 2) + 3(x^2 − x) = 2 x^2 + 2

c. x 0 = −1, x 1 = 0, x 2 = 1, x 3 = 2

P 3 (x) =

(x + 1)(x − 1)(x − 2) (0 + 1)(0 − 1)(0 − 2)

(x + 1)(x − 0)(x − 1) (2 + 1)(2 − 0)(2 − 1)

= −(x^3 − 2 x^2 − x + 2) + x^3 − x = 2 x^2 − 2

2 Approximate

2 using Neville’s method with f (x) =

x and x 0 = 0, x 1 = 1,x 2 = 4,x 3 = 9 and x 4 = 16.

Nevilles method looks like this:

function Q = neville(X,Q,x) n = length(X); for i = 2:n for j = 2:i Q(i,j) = (x-X(i-j+1))Q(i,j-1) - (x-X(i))Q(i-1,j-1); Q(i,j) = Q(i,j)/(X(i)-X(i-j+1)); endfor endfor endfunction

Pay attention to the indices, because octave/matlab counts from 1.

This generates:

octave:1> X=[0 1 4 9 16]; octave:2> Q=[0 1 2 3 4;zeros(4,1),zeros(4)]’ Q =

octave:3> neville(X,Q,2) ans =

0.00000 0.00000 0.00000 0.00000 0. 1.00000 2.00000 0.00000 0.00000 0. 2.00000 1.33333 1.66667 0.00000 0. 3.00000 1.60000 1.36667 1.60000 0. 4.00000 2.00000 1.53333 1.37778 1.

And we get

2 ≈ 1 .572. Notice that the square-root function is never called.

3 Find an error bound for approximating f (x) = sin(x) on the interval [0, π] with xi = iπ/ 2 for i = 0, 1 , 2.

|f (x) − P 2 (x)| =

f (3)(ξ) 3!

(x − x 0 )(x − x 1 )(x − x 2 )

| sin(x) − P 2 (x)| =

− cos(ξ) 6

(x − 0)(x − π/2)(x − π)

max 0 ≤x≤π

|(x)(x − π/2)(x − π)|

π^3 12