x_nodes = -5:5;
xx_nodes= -5:.5:5;
y_values = 1./(1+x_nodes.^2);
yy_values = 1./(1+xx_nodes.^2);

a=length(x_nodes);
b=length(xx_nodes);

t = min(x_nodes):.01:max(x_nodes);
runge=1./(1+t.^2);



hold all

%for i = 2:length(x_nodes)
    
divdif_y = divdif(x_nodes,y_values);
divdif_yy = divdif(xx_nodes,yy_values);

p_eval = interp(x_nodes,divdif_y,t);
pp_eval = interp(xx_nodes,divdif_yy,t);

M1=max(p_eval);m1=min(p_eval);
M2=max(pp_eval);m2=min(pp_eval);
M=max(M1,M2);m=min(m1,m2);
%axis([-5 5 m M])
axis([-5 5 -0.5 2])

figure(1)
title('Runge counterexample')
plot(x_nodes,y_values,'o', 'Color', 'green')
plot(xx_nodes,yy_values,'o', 'Color', 'black')
plot(t,runge,'Linewidth',2,'Color','red')
plot(t,p_eval,'Linewidth',2,'Color','blue')
plot(t,pp_eval,'Linewidth',2,'Color','yellow')
legend('interpolation 11 nodes','interpolation 21 nodes','1/(1+x^2)','\Pi_{11}','\Pi_{21}')

figure(2)
title('Runge counterexample. Error')
%plot(x_nodes,zeros(length(x_nodes)),'o', 'Color', 'green')
%plot(xx_nodes,zeros(length(xx_nodes)),'o', 'Color', 'black')
plot(t,runge-p_eval,t,runge-pp_eval)
legend('interpolation 11 nodes','interpolation 21 nodes')%,'err_\Pi_{11}','err_\Pi_{21}')