Docsity

Interpolation, Lecture Notes - Mathematics, Study notes of Calculus

Toggle sidebar
bg1
Math 128A Lab 4: Interpolation
Adrian Down
March 01, 2006
Part 1
Discussion
I compute the coefficients of the Newtonian interpolating polynomial using
the method of divided differences. Consider the value of the polynomial at
a given interpolated point,
p(x0) = c0+c1(x0−x0) + ...=c0
p(x1) = c0+c1(x1−x0) + c2(x1−x1) (x1−x0) = c0+c1(x1−x0)
.
.
.
p(xk) = c0+c1(xk−x0) + c2(xk−x1)(xk−x0) + ...+ck
k−1
Y
j=0
(xk−xj)
I use this cancellation property to solve for the coefficients ck,
p(x0) = c0
p(x1) = c0+c1(x1−x0)
⇒c1=c0−p(x1)
x1−x0
=p(x0)−p(x1)
x1−x0
This motivates the recursive definition,
p[x0] = p(x0)
p[x1] = p(x1)
p[x1, x0] = p[x1]−p[x0]
x1−x0
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Interpolation, Lecture Notes - Mathematics and more Study notes Calculus in PDF only on Docsity!

Math 128A Lab 4: Interpolation

Adrian Down

March 01, 2006

Part 1

Discussion

I compute the coefficients of the Newtonian interpolating polynomial using the method of divided differences. Consider the value of the polynomial at a given interpolated point,

p(x 0 ) = c 0 + c 1 (x 0 − x 0 ) +... = c 0 p(x 1 ) = c 0 + c 1 (x 1 − x 0 ) + c 2 (x 1 − x 1 ) (x 1 − x 0 ) = c 0 + c 1 (x 1 − x 0 ) .. .

p(xk) = c 0 + c 1 (xk − x 0 ) + c 2 (xk − x 1 )(xk − x 0 ) +... + ck

k∏− 1

j=

(xk − xj )

I use this cancellation property to solve for the coefficients ck,

p(x 0 ) = c 0 p(x 1 ) = c 0 + c 1 (x 1 − x 0 )

⇒ c 1 =

c 0 − p(x 1 ) x 1 − x 0

p(x 0 ) − p(x 1 ) x 1 − x 0

This motivates the recursive definition,

p[x 0 ] = p(x 0 ) p[x 1 ] = p(x 1 )

p[x 1 , x 0 ] =

p[x 1 ] − p[x 0 ] x 1 − x 0

In general,

p[x 0 ,... , xk] =

p[x 1 ,... , xk] − p[x 0 ,... , xk− 1 ] xk − x 0

It can be show that

ck = p[x 0 ,... , xk]

To find these coefficients, I construct a divided difference table of the form,          x 0 p(x 0 ) x 1 p(x 1 ) p[x 0 , x 1 ] x 2 p(x 2 ) p[x 1 , x 2 ] p[x 0 , x 1 , x 2 ] x 3 p(x 3 ) p[x 2 , x 3 ] p[x 1 , x 2 , x 3 ] p[x 0 , x 1 , x 2 , x 3 ] .. .

xn p(xn) p[xn− 1 , xn] p[xn− 1 , xn− 1 , xn] p[xn− 3 , xn− 2 , xn− 1 , xn]... p[x 0 , x 1 ,... , xn− 1 , xn]

The advantage of this table formation is that any given divided difference element can be computed as the difference of the element to the immediate left and the element immediately above that divided by the difference of the leftmost element of the row and an element of the leftmost row found by moving upwards diagonally from the location of the element to be calculated. The coefficients of the Newton form of the interpolating polynomial are the elements on the top of each column of this table, except for the first column, which does not correspond to any coefficient.

Code

function c = makepoly(x) % Function declaration range = 5; % Range in which intepolated values fall bin = 10000; % For plotting n = size(x); % Get size of matrix passed in np1 = n(2); % ’n plus one’ c = zeros(1,np1); % Coefficent matrix A = zeros(np1,np1+1); % Matrix of divided differences A(:,1) = x; % Initialize first and second columns A(:,2) = 1 ./ (1+x.^2);

mation depends on the number of mesh points n, the convergence of the approximating polynomial to the function is not uniform.

Results

−5^0 −4 −3 −2 −1 0 1 2 3 4 5

1 Polynomial approximation of degree 2 to 1/(1+x

(^2) ) 1/(1+x^2 ) p(x)

(a)

−0.4 −5 −4 −3 −2 −1 0 1 2 3 4 5

−0.

0

1 Polynomial approximation of degree 4 to 1/(1+x

(^2) ) 1/(1+x^2 ) p(x)

(b)

−0.4 −5 −4 −3 −2 −1 0 1 2 3 4 5

−0.

0

1 Polynomial approximation of degree 9 to 1/(1+x^2 ) 1/(1+x^2 ) p(x)

(c)

−0.5 −5 −4 −3 −2 −1 0 1 2 3 4 5

0

1

2 Polynomial approximation of degree 10 to 1/(1+x^2 ) 1/(1+x^2 ) p(x)

(d)

function x = makearray(n) for k = 1:n x(k) = 5cos(pi(2k+1)/(2n+2)); end end

I then find the interpolating polynomial by calling my function from part 1 above, makepoly(makearray(1+n)). As above, I find that increasing the number of mesh points increases the accuracy of the polynomial approximation. However, in this case, the approximating polynomial is symmetric only when n is even. In the case of n odd, there is a comparatively large error in the approximating polynomial near k = 5. This error is also decreased as the number of mesh points is increased.

Results

−5^0 −4 −3 −2 −1 0 1 2 3 4 5

1 Polynomial approximation of degree 2 to 1/(1+x

(^2) ) 1/(1+x^2 ) p(x)

(i)

−5^0 −4 −3 −2 −1 0 1 2 3 4 5

1 Polynomial approximation of degree 4 to 1/(1+x

(^2) ) 1/(1+x^2 ) p(x)

(j)

−0.5 −5 −4 −3 −2 −1 0 1 2 3 4 5

0

1

2

3

4

Polynomial approximation of degree 9 to 1/(1+x^2 ) 1/(1+x^2 ) p(x)

(k)

−5^0 −4 −3 −2 −1 0 1 2 3 4 5

1 Polynomial approximation of degree 10 to 1/(1+x^2 ) 1/(1+x^2 ) p(x)

(l)