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

Assignment 1

MATH 4NA3

13 January 2023

Due 27 January at 11:59pm

Instructions:

• Carefully read and answer all parts of each question. Four significant figures are sufficient for numerical answers.

• Ensure that your document is well organized and legible, with each question clearly labelled (e.g. 1(a), 1(b) etc.).

• Include any matlab code as well as its output. The code should have comments indicating the question it relates to and an explanation of what it is doing (use the % symbol for comments).

• Ensure that any figures are numbered, have labelled axes and a caption. The caption should include the figure number, the question it is related to and an explanation (e.g. “Figure 2(a): question 3. The total error in the fifirst order finite difference approximation for sin(1) illustrating the optimal step size and minimum error.”)

• Submit as a single pdf file on the Avenue dropbox by the due date.

Review exercises not to be handed in:

1. Review the matlab tutorials available on the course website.

2. What is the smallest positive integer which cannot be represented exactly in ieee arithmetic?

3. Which of the following statements are True or False?

• Using higher-precision arithmetic will make an ill-conditioned problem better conditioned.

• The choice of algorithm for solving a problem has no e↵ect on the propagated data error.

• A stable algorithm applied to a well-conditioned problem necessarily produces an accurate solution.

• Floating point numbers are uniformly distributed throughout their range.

• Increasing the number of data points always improves the interpolation error.

4. In a floating point system with base β, precision p and rounding to nearest, what is the maximum relative error in representing any nonzero real number within the range of the system.

Exercises to be handed in:

[6]          1 .    (a)    Write a matlab function that computes the  derivative of the Newton interpolant for a given set of data points at a user-defined vector of values .  [Hint:  consider the derivative of the  nested  multiplication  loop  of the  Newton  interpolation  algorithm  Newton.m to find a related algorithm for computing the derivative .]

Check your results by plotting the analytical derivative and the computed derivative for the function f(x) = tan(x) for N = 5 equally spaced data points on a dense grid of 200 points on the interpolation interval  [0 , T/4] .

[6]                  (b)    Compute  the  relative  l2  norm  of  the  error  of  the  interpolant  and  of  the  derivative approximation for f(x) = tan(x) on the dense grid for N = 4 , 12 , 20 , 28 , 36 , 44 , 52 , 60 , 68 equally spaced data points on the interpolation interval [0 , ⇡/4] . Comment on the results . How does the error of the derivative computed from the Newton interpolant compare to the the error of the interpolant itself?

2 .  Let f(x) = xx .  This question should be answered analytically  (i .e . do not use matlab) .

[6]                  (a)    Find the quadratic Lagrange polynomial P2(x) using the nodes x0 = 1,x1 = 1 .25,x2 = 1 .5.

[4]                  (b)    Use the polynomial from  (a) to estimate the average value of f(x) over the interval  [1, 1 .5] .

[4]                  (c)    Estimate the error in approximating f(x) with P2(x) .

3 .    (a)  Write a matlab program to interpolate

x    =    [    −5               −4               −3          −2          −1          0          1          2          3          4               5               ],

y    =    [    −0 . 1923    −0 .2353    −0 .30    −0 .40    −0 .50    0 .00    0 .50    0 .40    0 .30    0 .2353    0 . 1923    ] .

[4]                  (b)    Calculate error at the interpolated values at x = −4 .5 , −3 .5 , . . . , 3 .5 , 4 .5 compared with the exact function f(x) = x/(x2 + 1) .  Are these errors reasonable?

[6]                  (c)    Plot the exact function, the interpolating polynomial and the node points on the same graph . Where is the error the largest?  Comment .

[6]          4 .    (a)    Find the clamped cubic spline that passes through the points {(xk,f(xk))}k(3)=0 , on the graph of f(x) = x + 2/x, using the nodes x0  =  1/2,x1  =  1,x2  = 3/2,x3  = 2 .  Use the first derivative boundary conditions S\ (x0 ) = f\ (x0 ) and S\ (x3 ) = f\ (x3 ) .  Graph f  and the clamped cubic spline interpolant on the same coordinate system .   [You should use program csfit.m from Avenue, or simply compute the spline by hand .]

[6]                  (b)    Find the natural cubic spline that passes through the points  {(xk,f(xk))}k(3)=0 , on the graph of f(x) = x + 2/x, using the nodes x0  =  1/2,x1  =  1,x2  = 3/2,x3  = 2 .  Use the free boundary conditions  S\\ (x0 ) = 0  and  S\\ (x3 ) = 0 .   Graph  f  and the natural cubic spline interpolant on the same coordinate system .

[2]                  (c)    Comment on any di↵erences between the results you observed in  (a) and  (b) .

[Total:  50]