Consider the following function f 1 1 rightarrow R fx x Plo
Consider the following function f: [-1, 1] rightarrow R f(x) = |x| Plot the graph of the function f using MATLAB, and hand in the graph. Given n N\\{0}, define x_n^k = - 1 + 2k/n for 0 lessthanorequalto k lessthanorequalto n. Let g_n(x) be the unique polynomial of degree n which results by interpolating the n + 1 data {(x_n^k, f(x_n^k)}} for all 0 lessthanorequalto k lessthanorequalto n. (You can write a program to do it by any interpolation.) Plot the functions f, g_2, g_3, g_4 and g_5 on the same graph, and hand in the graph. Plot the sequence {g_n(0.3)}_1 lessthanorequalto n lessthanorequalto 20, and hand in the graph.
Solution
x = -1:0.2:1;
f = abs(x);
g2 = [];
g3 = [];
g4 = [];
g5 = [];
n = 2;
x2 = [];
for k=0:1:n
x2(end+1) = -1+2*k/n;
end
g2 = interp1(x, f, x2);
n=3;
x3 = [];
for k=0:1:n
x3(end+1) = -1+2*k/n;
end
g3 = interp1(x, f, x3);
n=4;
x4 = [];
for k=0:1:n
x4(end+1) = -1+2*k/n;
end
g4 = interp1(x, f, x4);
n=5;
x5 = [];
for k=0:1:n
x5(end+1) = -1+2*k/n;
end
g5 = interp1(x, f, x5);
figure
plot(x,f,\'bo\',x2,g2,\'go\', x3,g3,\'ro\',x4,g4,\'yo\',x5,g5,\'co\');
gn = []; %part c
for n=1:1:20
gn(end+1) = abs(-1+2*0.3/n);
end
plot((1:20), gn);
![Consider the following function f: [-1, 1] rightarrow R f(x) = |x| Plot the graph of the function f using MATLAB, and hand in the graph. Given n N\\{0}, define Consider the following function f: [-1, 1] rightarrow R f(x) = |x| Plot the graph of the function f using MATLAB, and hand in the graph. Given n N\\{0}, define](/WebImages/20/consider-the-following-function-f-1-1-rightarrow-r-fx-x-plo-1042947-1761542049-0.webp)