Question: please answer all parts. % % % Fourier DerivativeMatrix.m Returns nodal Fourier derivative matrix for an even number of grid $ points. See p33 of
please answer all parts.
% % % Fourier DerivativeMatrix.m 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 = FourierDerivativeMatrix(N) function D = FourierDerivativeMatrix(N) if(mod(N,2) ~= 0) err='Number N of nodal points must be even' pause end ind = [0:N-1]; row = repmat(transpose(ind), [1 N]); col = repmat(ind, IN 1]); % Shifts by eye(N) here avoid division by zero and also ensure diag(D) = 0. denom = sin(pi*(row-col)/N) + eye(N); numer = 0.5*(-1). (row+col).*(cos(pi*(row-col)/N) - eye(N)); D = numer./denom; 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 2 values via I'd = 2 (k-1)/N, for k=1,2,...,N. Assume throughout that N is an even integer. Define a column vector f with components fx = f(x), and a derivative matrix DERNXN with entries 3+k-2 ( dgk 0 if ;=k. The kth component gk of 9 Df then approximates the derivative value l'k). A MATLAB function Fourier DerivativeMatrix which returns D (for N even) is posted on UNM Learn. For f(x) = exp(sin r) use FourierDerivativeMatrix to approximate f'(t) as the component g(1+N/2) = 91+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 (still -1). Plot the set of errors versus N. What do you observe
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
