This preview shows page 1. Sign up to view the full content.
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
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
This document was uploaded on 10/10/2013.
- Fall '13
- Numerical Analysis