Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
MATH 348 HW
Due Monday March 14 on BrightSpace by midnight
1. (10 points) Write a Python function named GaussLegendre to calculate Gauss-Legendre integration
ˆ 1
−1
f(x)dx =
n∑
i=1
wif(xi)
where {xi}ni=1 are the roots of the the degree-n Legendre polynomial Ln, which satisfied the recursive rela-
tionship
(n+ 1)Ln+1(x) = (2n+ 1)xLn(x)− nLn−1(x)
for n = 1, 2, 3, . . ., with L−1(x) = 0 and L0(x) = 1.
• Arguments:
– f: the integrand, a function
– n: the degree of the Legendre polynomial to compute xi, an integer.
• Return the Gauss-Legendre approximation of the integral, a float value.
2. (10 points) Extend the method to evaluate
ˆ b
a
g(x)dx. Note that the Legendre polynomials are orthogonal
on the integral [−1, 1], so a change of variuable is needed.
(a) (5 points) Write a Python function named GaussLegendre2 (you may use the GaussLegendre function
in Question 1).
• Arguments:
– g: the integrand, a function
– a, b: the integral limits, float values
– n: the degree of the Legendre polynomial to compute xi, an integer.
• Return the Gauss-Legendre approximation of the integral, a float value.
(b) (5 points) Use the function GaussLegendre2 to evaluate
ˆ pi/2
−pi/2
cosxdx, with n = 6, and compute the
error (the true value is 2). Find the step size h needed for the Simpson’s method to reach the same error.
3. (10 points) Suppose the function f(x) is smooth enough.
(a) (5 points) Theoretically estimate the error of Gauss-Legendre integral
´ b
a
f(x)dx for a given n.
(b) (5 points) Compare with the results in Question 2(b).