hw8_part2_solutions

# hw8_part2_solutions - ylabel'f(x Problem 5 MATLAB Command...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem 4
MATLAB Command Window EDU>> HW8_Prob4 MATLAB m-file HW8_Prob4.m % original function xx = linspace(-1,1,100); yy_o = 1./(1+25*xx.^2); % part a x = linspace(-1,1,11); xa = x; y = 1./(1+25*x.^2); ya = y; p = polyfit(x,y,length(x)-1); pa = p; yy = polyval(p,xx); yy_a = yy; % part b i = 1:11; x = cos((2*i-1)/11*pi/2); xb = x; y = 1./(1+25*x.^2); yb = y; p = polyfit(x,y,length(x)-1); pb = p; [yy] = polyval(p,xx); yy_b = yy; % plot plot(xx,yy_o,'k'); hold on; plot(xa,ya,'om'); plot(xb,yb,'ob'); plot(xx,yy_a,'m') plot(xx,yy_b,'b') legend('original function','evenly spaced points','Chebysev points','polynomial by even spaced points','polynomial by Chebysev points') title('Comparison of Runge''s function with 10th-order polynomials') xlabel('x')

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document