# runge: The Runge phenomenon for polynomial interpolation # wild oscillations for large degree polynomials. runge := proc(n) # n is the degree of the polynomial local f, xp, yp, i, poly, p1, p2, caption; f := x -> 1 / (1+x^2); xp := [ seq(-5+i*10/n, i=0..n) ]; yp := map(f,xp); poly := interp(xp,yp,x); caption := cat(`degree = `, n); p1 := plot(f(x), x=-5..5, y=-2..2, numpoints=401); p2 := plot(poly, x=-5..5, y=-2..2, numpoints=401, color=red); plots[display]([p1,p2], title=caption); end: # f is an even function so we should use even degree polynomials for n in [2,4,10,20,50,100] do interface(plotdevice=gif, plotoutput=`runge`.n.`.gif`); runge(n); od;