Docsity

Lagrange Interpolation and Composite Trapezoidal Rule, Assignments of Mechanical Engineering

Toggle sidebar
bg1
1
MCEN 3030: Homework 4 (100pts)
Due date: Monday, March 6th, 2006 at the beginning of the lecture.
Polynomials (60pts)
The Lagrange interpolation formula for a function f: [a, b]→Ris
PN(x) =
N
X
j=0
f(xj)LN,j (x) (1)
with error term
f(x) = PN(x) + f(N+1)(ξ(x))
(N+ 1)! (x−x0)(x−x1)...(x−xN) (2)
where Nis the degree and ξ∈(a, b). Remember that the LN,j (x) have the
property LN,j (xj) = 1 and LN,j (xk) = 0 (i6=k). Elsewhere they are defined as
LN,j (x) =
N
Y
i=0,i6=j
(x−xi)
(xj−xi).(3)
A) Write a matlab function computing the LN,j(x) for a given N,j, a vector of
nodes {xi}N
i=0 and a given x.
B) Write a matlab function computing PN(x) for a given N,x, a vector of points
and function evaluation {xi, f(xi)}N
i=0.
Suppose that the function of interest is
f(x) = 1
1 + 25x2
on [a, b] = [−1,1].
With equidistant points, on the interval [−1,1], construct the polynomials P4,
P8,P16. (ex: for P4we need 5 points: −1,−0.5,0,0.5,1)
C) Plot each one of your polynomial reconstruction using the vector xfine(l) =
−1 + 2
M−1(l−1) with M= 100. Superpose each (line) plot of the polynomials
and add a label containing the polynomial order (to distinguish them) from each
other. As a title put ”The Runge Function Interpolated with Lagrange”.
D) Do the same as in C but plot the maximum absolute difference between f
and PN. Put as a title ”Interpolation Error for Runge Function Interpolated
with Lagrange”.
What to return: Printout the graphics in C and D and mail all the m files.
The TA will do random checks for the codes and will correct each graphic.
pf2

Partial preview of the text

Download Lagrange Interpolation and Composite Trapezoidal Rule and more Assignments Mechanical Engineering in PDF only on Docsity!

MCEN 3030: Homework 4 (100pts)

Due date: Monday, March 6th, 2006 at the beginning of the lecture.

Polynomials (60pts)

The Lagrange interpolation formula for a function f : [a, b] → R is

PN (x) =

∑^ N

j=

f (xj )LN,j (x) (1)

with error term

f (x) = PN (x) +

f (N^ +1)(ξ(x)) (N + 1)!

(x − x 0 )(x − x 1 )...(x − xN ) (2)

where N is the degree and ξ ∈ (a, b). Remember that the LN,j (x) have the property LN,j (xj ) = 1 and LN,j (xk) = 0 (i 6 = k). Elsewhere they are defined as

LN,j (x) =

∏^ N

i=0,i 6 =j

(x − xi) (xj − xi)

A) Write a matlab function computing the LN,j (x) for a given N , j, a vector of nodes {xi}Ni=0 and a given x.

B) Write a matlab function computing PN (x) for a given N , x, a vector of points and function evaluation {xi, f (xi)}Ni=0.

Suppose that the function of interest is

f (x) =

1 + 25x^2

on [a, b] = [− 1 , 1]. With equidistant points, on the interval [− 1 , 1], construct the polynomials P 4 , P 8 , P 16. (ex: for P 4 we need 5 points: − 1 , − 0. 5 , 0 , 0. 5 , 1)

C) Plot each one of your polynomial reconstruction using the vector xf ine(l) = −1 + (^) M^2 − 1 (l − 1) with M = 100. Superpose each (line) plot of the polynomials and add a label containing the polynomial order (to distinguish them) from each other. As a title put ”The Runge Function Interpolated with Lagrange”.

D) Do the same as in C but plot the maximum absolute difference between f and PN. Put as a title ”Interpolation Error for Runge Function Interpolated with Lagrange”. What to return: Printout the graphics in C and D and mail all the m files. The TA will do random checks for the codes and will correct each graphic.

Composite Integration (40pts)

E) We saw in class that one of the Newton-Cotes quadrature rule is

∫ (^) a

b

f (x)dx =

h 2 (f (a) + f (b)) −

h^3 12 f (2)(ξ) (4)

with h = b − a on an interval [a,b] (aka the trapezoidal rule). Construct the composite formula associated with this rule (Use x 0 = a and xN = b with h = b−Na ) and find the error term associated with it.

F) Code the composite trapezoidal rule in matlab to integrate an arbitrary function f (use feval(f,x) and passing a function to a function requires @). For the simple function f (x) = sin(x) integrated on [0, 2] verify your experimental order of convergence with the formula:

p =

log(|eh/e h 2 |) log(2)

where eh is the difference between your composite trapezoidal rule and the true value of the integral. For the experiment use 50 and 100 points.

What to return: All your derivations in E on paper and the output for p your are getting (cut and paste matlab session): mail your composite rule m-file with all the other files requested.