matlab job

HERE

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Numerical Analysis – MATH3806/COMP3806
Carleton University Fall

2

0

1

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

3

Assignment #3 – Due November 22th

Exercise 1 – Part A

Let x1, . . . ,xn be n distinct real numbers and y1, . . . ,yn are n real numbers (not necessarily
distinct). One denotes by ω0(X) = 1, ωj(X) = (X − x1) · · · (X − xj) for j = 1, . . . ,n.

Let

P be the Lagrange interpolation polynomial at (x1,y1), . . . , (xn,yn) and let α0, . . . ,αn−1 its
components in the basis ω0, . . .ωn−1 of Rn−1[X].
For 1 6 j 6 n−1, the polynomial

j−1∑
k=0

αkωk is the Lagrange polynomial at (x1,y1), . . . , (xj,yj).
For 1 6 i 6 j 6 n, one denotes di,j the coefficient of X

i−1 in the Lagrange polynomial at the
points (xj−i+1,yj−i+1), . . . , (xj,yj) (this polynomial belongs to Ri−1[X]). One has d1,j = yj
for 1 6 j 6 n. Moreover for 2 6 i 6 n, recall that

di,j =
di−1,j − di−1,j−1
xj − xj−i+1

for i 6 j 6 n. (1)

The di,j (i 6 j 6 n) are called the divided differences at the points (x1,y1), . . . , (xn,yn).
One can iteratively compute these numbers d2,j (2 6 j 6 n), then the d3,j (3 6 j 6 n) etc.
to dn,n. By definition of dj,j, one has dj,j = αj−1 then

P =
n∑

j=1

dj,j ωj−1. (2)

1) One assumes that the xi (resp. yi) are stored in a line vector x (resp. y) of length n.
Write an matlab algorithm that computes the d1,1, . . . ,dn,n and store them in d, a line vector
of length n. Remark that one can initialize d with y1, . . . ,yn and transform it such that it
contains successively d1,1, . . . ,di,i,di,i+1, . . . ,di,n for i = 1, and for i = 2, etc. and finally for
i = n. One will then use only the vector d.
2) Let xt be a vector of m real numbers, write an algorithm that computes yt the values of
the polynomial P at xt(k) for k = 1, . . . ,m.
3) Write a matlab function : function [yt]=interp(x,y,xt) – where the line vector x
contains x1, . . . ,xn and where the line vector y contains y1, . . . ,yn – that computes yt from
xt.
4) Determine analytically the 2 interpolation polynomials defined by

• x = [0, 1] and y = [2, −1], • x = [0, 1, 2] and y = [2, −1, 0],

then draw the graph of this polynomial on the interval [−1, 3] using their expression and
then using the function interp.

1

Exercise 1 – Part B

Let

f(x) =
1

(x − 0.5)2 + 0.05
.

For i = 1, . . . ,n + 1, one sets xi = −1 + (i − 1)h with h = 2/n. One denoted Pn the
interpolation polynomial of f at x1,x2, . . . ,xn+1.
1) Write a matlab code that, for n given, builds the vector of the xi, then the vector of the
f(xi). One could test the code by taking n = 1, 2, 3.
2) For n = 1, 2, 3, 4, 5, 6, represent on the same figure (using the function subplot) the
graphs of f(x) and of Pn(x) on the interval [−1, 1] with a marker at the interpolation points.
One will take a graphical window [−1, 1] × [−5, 25].

2

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER