Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Plotting Your task is to reproduce the following figure as accurately as you are

ID: 3209654 • Letter: P

Question

Plotting Your task is to reproduce the following figure as accurately as you are able. A Visualization of the Runge Phenomenon 0.01 r 0.005 Even Spacing Chebyshev This is bad -0.005 -0.01 1 08 004 02 002 04 06 08 Polynomial interpolation with 10 nodes 1.5 125r2 - Even spacing Chebyshev 0.5 -0.5 -108 06 0.402 0 0.2 04 06 081 Notes on the functions shown in the plots: 1. Given a set of (interpolation) points ro,., z, the function w is defined as w(z) = 11(z-z.), and is related to the error bounds for polynomial interpolation. This means that the w(x) defined using evenly spaced nodes will not be the same as the w(x) defined using Chebyshev nodes. 2. The main function in the second subplot is f(z) = 1/(1 + 25?), and the functions graphed in blue and red are the polynomial interpolations of f(x) using evenly spaced nodes and Chebyshev nodes, respectively. Your function Interpolate from HW4 should give you all the data you need for the second plot.

Explanation / Answer

ANSWER:

MATLAB code for calculating interpolation nodes and interpolation polynomial:

------------------------------------------------------------------------------------

function [xk, p] = Interpolate(f,a,b,n,spacing)
if strcmp(spacing,'')
xk = linspace(a,b,n+1);
elseif strcmp(spacing,'chebyshev')
k = 1:n+1;
xk = 0.5*(a+b)+0.5*(b-a)*cos((2*k-1)*pi./(2*(n+1)));
end
y=f(linspace(a,b,n+1));
polyCoeffs = polyfit(xk,y,n);
p = @(x)(sum(polyCoeffs.*[x.^(n:-1:0)]));

------------------------------------------------------------------------------------------

MATLAB code for plotting w(x)

-------------------------------------------------------------------------------------------

n = 10;
f = @(x)(1./(1+25*x.^2));
[xk, p]= Interpolate(f,-1,1,n,'');
[x1k, q] = Interpolate(f,-1,1,n,'chebyshev');

wx = @(x)((x-xk(1))*(x-xk(2))*(x-xk(3))*(x-xk(4))*(x-xk(5))*(x-xk(6))*...
(x-xk(7))*(x-xk(8))*(x-xk(9))*(x-xk(10))*(x-xk(11))); % w(x) defined by evenly spaced nodes
w1x = @(x)((x-x1k(1))*(x-x1k(2))*(x-x1k(3))*(x-x1k(4))*(x-x1k(5))*(x-x1k(6))*...
(x-x1k(7))*(x-x1k(8))*(x-x1k(9))*(x-x1k(10))*(x-x1k(11))); % w(x) defined by chebyshev nodes
  
MATLAB code for plotting w(x)


fplot(wx,[-1 1]);
ylim([-0.01 0.01]);
xlabel('x');
ylabel('w(x)');
hold on; grid on;
fplot(w1x,[-1 1]);
legend('Even Spacing', 'Chebyshev');

MATLAB code for plotting interpolation polynomial


figure;
fplot(f,[-1 1]);
xlabel('x');
ylabel('f(x)');
hold on;grid on;
fplot(p,[-1 1]);
hold on;
fplot(q,[-1 1]);
legend('1/1+25x^2','even spacing','chebyshev');