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

MATH2601

Computational Assessment


Write your work in a Python Jupyter Notebook called X.ipynb, where X is your student ID number (not your login), then submit it to the Assessment area (Submit My Work)for MATH2601 on the VLE.

Jupyter Notebooks allow you to write Python programmes in Code Cells and to produce an analysis ofyour results using Markdown Cells with embedded LATEXcommands.

 

Question 1  Fourier Series   [25 marks]

The Fourier series of a 2几-periodic function u(x) is


u(x) =    k eikx,

=−∞

(1)

where the Fourier coefficients are given by

k =2几(1) \0 2 u(x) eikx dx,                           (2)

with k ∈ Z and i = − 1. We shall compute numerically the Fourier series of the 2几-periodic function

k =  2        1             for all k ∈ Z .                              (3)

1 − 4k2 ,

1.  Write a function dft(u,N,k) that evaluates k , the k-th Fourier coefficient of an arbitrary function u(x), by computing the integral (2) using the N-point composite trapezium rule,

\0 2 f (x)dx N(2几)  f (xj), were xj = 2N(几j) .                 (4)

2.  Plot, on the same graph, the exact discrete values of k, given by (3), as well as approximations

obtained using your function dft with N = 5 and with N = 11, for 5 5. Comment on

3.  In order to be evaluated numerically, the series (1) must be truncated such that

+kmax

u(x) ≈ p(x) =       k eikx .

k= kmax

Write a function p(u,x,kmax)that evaluates the truncated series (5), for an arbitrary function u, at an array of points x.  The Fourier coefficients k will be estimated using your function dft with N = 2kmax + 1.

4.  Plot, on the same graph, the function v(x) for x ∈ [0,4几], as well as the approximations p(x) for kmax  = 3 and for kmax  = 50. Choose the points x so that the plots look smooth. Comment on your results.

Question 2  Gaussian Quadrature    [25 marks]

We wish to approximate the integral of a function f using the N-point Gauss quadrature,

\ f (x) dx  wkf (xk),

where xk is the k-th root of the Legendre polynomial PN(x), of degree N, and

wk =               2              

( 1 x k(2)) PN(′2)(xk) .

(6)

(7)

We shall only consider the case N = 5, using the fifth Legendre polynomial and its first derivative

P5(x) =  (63x5 70x3 + 15x)    and    P5(′)(x) =  (315x4 210x2 + 15) .        (8)

1.  Write a function Newton(P,dP,x0) which implements Newton’s method to compute an ap- proximation of a root of a polynomial P, with an error less than 1010 .  The arguments P and dP are functions computing the value of the polynomial, P(x), and its first derivative, P(x), respectively; x0 is an initial guess for the root.

2.  Starting with initial guesses given by the Chebyshev points

zk = cos ( 2 2(k) 1 ) , k = 1, . . . , N,                      (9)

use your function Newtonto compute the five roots xk , k = 1, . . . , 5, of the Legendre polynomial P5 . Then, calculate the corresponding weights, wk, given by (7).

3.  Evaluate the errorfunction, erf(x), at the point x = 1,

erf(1) =  \0 1 ex2 dx,

(10)

using the five-point Gauss method (6) and your values for the quadrature points, xk, and for the weights, wk, for k = 1, . . . , 5.