Question: PLEASE DO IN MATLAB 3. Here we approximate f(x) for a periodic function f(x) defined on [0,2] using a nodal Fourier method (please don't worry
PLEASE DO IN MATLAB
![function f(x) defined on [0,2] using a nodal Fourier method (please don't](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3c5c1e4b06_90566f3c5c163a34.jpg)

3. Here we approximate f(x) for a periodic function f(x) defined on [0,2] using a nodal Fourier method (please don't worry if you have never heard of such). Define a grid of x values via xk=2(k1)/N,fork=1,2,,N. Assume throughout that N is an even integer. Define a column vector f with components fk= f(xk), and a derivative matrix DRNN with entries djk=21(1)j+k2cot((jk)/N)0ifj=kifj=k The k th component gk of g=Df then approximates the derivative value f(xk). A MatLaB function FourierDerivativeMatrix which returns D (for N even) is posted on UNM canvas. For f(x)=exp(sinx) use FourierDerivativeMatrix to approximate f() as the component g(1+N/2)=g1+N/2. That is, approximate f() as the (1+N/2) st component of Df. For N=4,8,12,16,20,24,28,32,36 compute the error (in absolute value) between the approximation and the exact answer f()=1. Plot the set of errors versus N. What do you observe? \% Returns nodal Fourier derivative matrix for an even number of grid \% points. See p33 of "Spectral Methods for Time-Dependent Problems" by \% Hesthaven, Gottlieb, and Gottlieb (Cambridge University Press 2007). \% Evaluation here is compact with Matlab's repmat in lieu of loops. So \% the code is somewhat opaque. \% function D = FourierDerivativelatrix(N) function D= FourierDerivativellatri x(N) if (mod(N,2)0) err='Number N of nodal points must be even' pause end ind =[0:N1]; row =repmat(transpose( ind ),[1N); col = repmat ( ind,[N1); \% Shifts by eye(N) here avoid division by zero and also ensure diag(D) =0. denom =sin(pi(rowcol)/N)+eye(N); numer =0.5(1)(row+col),(cos(pi(rowcol)/N)eye(N)) D= numer. / denom
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
