% code for fitting cubic spline with Matlab's default not-a-knot end % condition to the famous Runge function 1/(1+x^2) clear; a=-5;b=5;n=10; xknots = linspace(a,b,n+1); yknots = 1./(1+xknots.^2); % calculate the spline; information in pp pp=spline(xknots,yknots); % now evaluate it on a fine grid; neval=100; xeval = linspace(a,b,neval); yeval=ppval(pp,xeval); % plot it, showing knots figure(1); plot(xknots,yknots,'o',xeval,yeval,'-'); xlabel('x'); ylabel('f'); title('Cubic spline for 1/(1+x^2) with n=10');