# M you can skip the comments 2 x linspace 1121 fx

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for 0 ≤ j ≤ 2 × 105 . Enter the code into a Matlab script (not the command window) and save it as “lab2 task1.m”. You can skip the comments. 2 x = linspace(-1,1,21); fx = exp(-(x.^2)*20); a = polyfit(x,fx,20); % 21 nodes uniformly distributed in [-1,1] % evaluate f at the nodes % compute the coefficients of P_20 y = linspace(-1,1,2e5+1); % 200001 points uniformly distributed in [-1,1] fy = exp(-(y.^2)*20); % evaluate f at the 200001 points Py = polyval(a,y); % evaluate P_20 at the 200001 points format long E = max(abs(fy-Py)) % compute the maximum absolute error in the fine grid 2. Repeat the above code, but with diﬀerent sets of 21 distinct nodes. This can be done by entering the values manually (e.g. replace the ﬁrst line by“x = [-0.999, ..., 1];”) or by applying some transformation to the uniformly distributed “x” (e.g. add the line “x = x.*abs...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online