453 Homework assignment 5, due Friday Oct 24, 2014, by 9 am..

1
CAAM 453: Numerical Analysis I
Problem Set 5
Due: October 24st 2014 by 9am (beginning of class).
Note: All M ATLAB functions mentioned in this homework assignment can be found on
the CAAM453 homepage, or come with M ATLAB . You can use the M ATLAB codes
posted on the CAAM453 web-page. If you modify these codes, please turn in the
modified code. Otherwise you do not have to turn in printouts of the codes posted on
the CAAM453 web-page. Turn in all M ATLAB code that you have written and turn
in all output generated by your M ATLAB functions/scripts. M ATLAB functions/scripts
must be commented, output must be formatted nicely, and plots must be labeled.
Problem 1 (40 points)
Legendre Polynomials Pn (x) ∈ Pn are solutions of the Legendre equation:
d
2 d
(1 − x ) Pn (x) + n(n + 1)Pn (x) = 0.
dx
dx
(1)
Each Legendre polynomial Pn (x) is an nth-degree polynomial. It may be expressed using
Rodrigues’ formula:
1 dn 2
n
Pn (x) = n
(x
−
1)
.
(2)
2 n! dxn
You are going to demonstrate that those Pn ’s are (to a constant) the orthogonal polynomials
we discussed in class.
• Show that the Pn ’s defined through Rodrigue’s formula (2) satisfy (1).
• Show that Legendre Polynomials Pn (x) can be computed using the following recursion
formula
(n + 1)Pn+1 (x) = (2n + 1)xPn (x) − nPn−1 (x)
with P0 = 1 and P1 = x.
• Show that
0
0
Pn+1
(x) − Pn−1
(x) = (2n + 1)Pn (x).
• Show that
Pn (1) = 1, Pn (−1) = (−1)n , Pn (−x) = (−1)n Pn (x).
• Orthogonality: show that
Z 1
−1
Pn (x)Pm (x)dx =
2
δmn .
2n + 1
For m 6= n, use the fact that both Pn and Pm satisfy (1). For m = n, use Rodrigue’s
formula (2).
2
• Compute
Z 1
0
Pn (x)dx.
• Compute
Z 1
−1
Pn0 (x)Pm (x)dx.
• Show that
P2n+1 (0) = 0
and P2n (0) = (−1)n
(2n)!
22n (n!)2
.
• In one single MATLAB figure, draw Pn (x), x ∈ [−1, 1], for n = 0, . . . , 5.
Problem 2 (30 points)
The steady temperature distribution T (x, y, z) inside the sphere of radius a satisfies the Laplace
equation
∂2 T ∂2 T ∂2 T
∇2 T = 2 + 2 + 2 = 0.
∂x
∂y
∂z
Spherical coordinates are defined as
x = r sin θ cos ϕ,
y = r sin θ sin ϕ,
z = r cos θ,
r ∈ [0, a], θ ∈ [0, π] and ϕ ∈ [0, 2π[. Laplace equation can be written in spherical coordinates
as
2
∂2
∂
1
∂
1
2 ∂
∂
2
∇ T (r, θ, ϕ) =
T
+
sin
θ
T
+
+
T.
∂r2 r ∂r
r2 sin θ ∂θ
∂θ
r2 sin2 θ ∂ϕ2
• Assume that the temperature inside the sphere is independant of ϕ. In this case, the
method of separation of variables allows us to write T as a series of Legendre polynomials
∞ Bn
n
T (r, θ) = ∑ An r + n+1 Pn (cos θ).
(3)
r
n=0
In (3), An and Bn are parameters. Equation (3) is the solution of Laplace equation for
any choice of An and Bn .
If we heat the surface of the sphere i.e. we impose a fixed distribution of temperature
on its surface:
T (a, θ) = f (θ),
(4)
3
find the unique set of coefficients An and Bn for which the solution (3) on r = a and the
boundary condition (4) match.
Hint: T should remain finite for r = 0.
Hint: posing x = cos θ, the orthogonality relation of Legendre polynomials transforms
to
Z 1
Z 0
2
δmn .
Pm (x)Pn (x)dx =
Pm (cos θ)Pn (cos θ)(− sin θ)dθ =
2n + 1
−1
π
Coefficients An can then be obtained computing
Z 0
Z 0
T (a, θ)Pm (cos θ)(− sin θ)dθ =
π
f (θ)Pm (cos θ)(− sin θ)dθ
π
• Let us heat the north hemisphere and leave the southern half cold. So, f (θ) = 1 for
0 ≤ θ ≤ π/2 and f (θ) = 0 for π/2 < θ ≤ π. Compute explicitely T (r, θ). For that, use
some of the results demonstrated in problem 1.
• Calculate the temperature at the center of the sphere.
• Using MATLAB, produce color plots of the temperature T in the r, θ plane using a
finite number of modes, i.e. using equation (3) with n = 1, . . . , N. Use N = 2, N = 10
and N = 100 modes.
Problem 3 (30 points) this problem is pledged
Write a MATLAB program that computes a polynomial interpolation at order n of a function
f using n + 1 interpolation points {x j }nj=0 .
The calling sequence should be
p
=
polynomial_interp(x,f);
Input:
x
is a vector of size n+1 that contains interpolation points
f
is a handle to the function
Output:
p
is a vector of size n+1 that contains the coefficents of the
nth order polynomial that interpolates f at x
4
You are allowed to use the in-house Matlab vander function (type help vander for help in
Matlab interface) and the backslash command to solve linear systems.
Consider the now famous Runge function
f (x) =
1
.
1 + x2
Compute a polynomial interpolant to Runge’s function at order n in the range x ∈ [−5, 5]
using the following systems of interpolation points:
• Use n + 1 equi-spaced points,
• Use the n + 1 roots of the degree-(n+1) Chebyshev polynomial,
• Use the n − 1 roots of the degree-(n-1) Legendre polynomial, plus the two endpoints of
the interval.
Compare the three interpolants and the true function graphically by superimposing the graphs
of the three polynomial interpolants and f on the same plot (be sure to include a legend).
Use n = 11 and then n = 21 (one plot for each n).
Then, compute
k f − pn kL∞ [−5,5]
and report that value on a graph for n = 1, . . . , 21 using the three systems of interpolation
points.