Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Homework 5

AMATH 352, Fall 2022

Warm up

Look up the following functions and commands in Python:

• Generating a uniform set of points in an interval: numpy .linspace

• Constructing Vandermonde matrices: numpy .vander

• Solving matrix equations and computing determinants: numpy .linalg .solve, numpy .linalg .det

• Trigonometric functions in numpy: numpy .sin and numpy .cos

• Creating high quality plots with matplotlib .pyplot, labeling axes and legends, setting figure sizes and axis limits.

Problem Description

Your goal in this HW is to interpolate Runge’s function and investigate the numerical accuracy and stability of this problem.

Part I

1.  Consider the function

f() =  ,         ∈ [ −1, 1].

and let  = (0 , . . . , N1) ∈ RN  be a uniform grid of N points in the interval [ −1, 1], i.e, j  =  − 1.

Your goal is to find a polynomial

N1

P () = ∑⃞ akk ,         ∈ [ −1, 1],

k=0

of degree less than or equal to N − 1, that interpolates f at the points   .

2.  Take N = 23 , 24 , 25, construct the Vandermonde matrix V ∈ RN×N, and the right hand side vector y = (f(0 ),f(1 ), . . . ,f(N1)) ∈ RN .

3.  Solve the linear system

 a = y ,

to find the coefficients aj .

4.  For each value of N plot your interpolating polynomial, obtained with the uniform j’s, along with the true function f and report the determinant of V .

Hint:  use a fine uniform grid of 100 points to plot your functions for good visualization. Make sure to generate legends if you plot multiple functions on the same figure and set your y -axis limits to [0, 1.1] to make the functions visible. I suggest you plot all three of your interpolants along with f on the same figure to save space.

5.  Repeat the above steps by replacing the uniform points j  with the Chebyshev nodes j  = cos(⃞  )⃞ ,        j = 0, . . . ,N − 1.

6.  For each value of N plot your new interpolating polynomial, obtained with the Chebyshev j’s, along with the true function f and report the determinant of V .

7.  Discuss your results. How does the choice of interpolating points affect the quality of the interpolating polynomial? how does it affect the determinant of V?

Part II

8.  Your goal in the second part is to repeat the experiments of Part I with your interpolating polynomial replaced with a trigonometric polynomial

T () = 1 ak cos(k) +  ak sin (⃞(⃞k  + 1)⃞)⃞ .

k=0                                        k=2(N)

9.  Take  to be the same set of uniform interpolation points as in Step 1 and formulate the corresponding linear system Aa = y whose solution gives the coefficients aj .  Explain your derivation of A in the theory part of your report.

10.  For each value of N plot your trigonometric interpolant, obtained with the uniform 北j ’s, along with the true function f and report the determinant of A.

11.  Repeat the above experiments but this time take  to be the Chebyshev points.

12.  For each value of N plot your trigonometric interpolant, obtained with the Chebyshev 北j ’s, along with the true function f and report the determinant of A.

13.  Discuss your results. How does the choice of interpolating points affect the quality of the trigonometric interpolant? how does it affect the determinant of A? and how do your results compare with Part I?