Interpolation program not graphing

40 Views Asked by At

I'm using this program for my Elementary Numerical Analysis class. This creates an interpolant of degree n to the function fcn(x) on $[-1,1]$, which is given below by a function subprogram. The nodes are the Chebyshev zeroes of the degree $n+1$ Chebyshev polynomial on $[-1,1].$ The program gives two plots: first the true function and its interpolant, and second, the error in the interpolation.

Does anyone know why I'm not able to see the graphs made by this program? I'm not sure why the program doesn't create them. I'm not too familiar with Matlab so I don't know what the reason could be.

function [nodes, fcn_values, div_diff_fcn] = chebyschev_interp(n)

%create the nodes and associated divided differences
h  = pi/(2*(n+1));
nodes = cos(h*[1:2:2*n+1]);
fcn_values = fcn(nodes);
function div_diff_fcn = divdif(nodes,fcn_values)

%Created the points at which the functions are to be graphed
x_eval = -1:.002:1;
true_fcn = fcn(x_eval);
y_eval = interp(nodes,div_diff_fcn, x_eval);

%create the window for the graph of the function and its interpolant
m = min([min(true_fcn), min(y_eval)]);
M = max([max(true_fcn),max(y_eval)]);
axis([-1.1,1.1,m,M])
hold on

%create the graph of the function and its interpolant
plot(x_eval, true_fcn, 'r')
plot(x_eval,y_eval, ':')
legend('True function','Interpolant',0)
plot(nodes,fcn_values, '.','MarkerSize',6)
hold off
pause
clf

%create the window for the graph of the error .
error = true_fcn - y_eval;
M = max(error);
m = min(error);
axis(-1.1,1.1,m,M)
hold on

%create the graph of the error in the interpolatant
plot(x_eval, error, 'r')
hold off

%print the maximum error
disp(['maximum error =', num2str(max(abs(error)))])

function fval = fcn(x)
fval = exp(x);
```