Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
\\ adapted from an original idea by Ilya Zakharevich12\\ generate an RGB color triple from a "magnitude" between 0 and 2553\\ (low = close to a cold blue, high = close to a hot red).4\\ To generate simple colormaps.5rgb(mag) =6{ my(x = mag/255., B, G, R);7B = min(max(4*(0.75-x), 0), 1);8R = min(max(4*(x-0.25), 0), 1);9G = min(max(4*abs(x-0.5)-1, 0), 1);10return (floor([R, G, B]*255));11}12default(graphcolormap, concat(["white","black","blue"], vector(25,i,rgb(10*i))));13default(graphcolors, vector(25,i,i+2));1415\\ plot Taylor polynomials of f,16\\ of index first + i*step <= ordlim, for x in [xmin,xmax].17plot_taylor(f, xmin=-5, xmax=5, ordlim=16, first=1, step=1) =18{19my(T,s,t,w,h,dw,dh,cw,ch,gh, extrasize = 0.6);20my(Taylor_array);2122default(seriesprecision,ordlim+1);23T = f('q);24ordlim = (ordlim-first)\step + first;25Taylor_array = vector(ordlim+1);26forstep(i=ordlim+1, 1, -1,27T += O('q^(1 + first + (i-1)*step));28Taylor_array[i] = truncate(T)29);3031t = plothsizes();32w=floor(t[1]*0.9)-2; dw=floor(t[1]*0.05)+1; cw=t[5];33h=floor(t[2]*0.9)-2; dh=floor(t[2]*0.05)+1; ch=t[6];3435plotinit(2, w+2*dw, h+2*dh);36plotinit(3, w, floor(h/1.2));37\\ few points (but Recursive!), to determine bounding box38s = plotrecth(3, x=xmin,xmax, f(x),39"Recursive|no_X_axis|no_Y_axis|no_Frame", 16);40gh=s[4]-s[3];4142plotinit(3, w, h);43plotscale(3, s[1], s[2], s[3]-gh*extrasize/2, s[4]+gh*extrasize/2);44plotrecth(3, x=xmin,xmax, subst(Taylor_array, 'q, x), "no_Rescale");45plotclip(3);46plotcopy(3, 2, dw, dh);4748plotmove(2, floor(dw+w/2-15*cw), floor(dh/2));49plotstring(2, "Multiple Taylor Approximations");50plotdraw(2);51}5253\p954plot_taylor(sin)55plot_taylor(exp,-3,3)56plot_taylor(x->besselk(2,x), 1,5)57plot_taylor(x->1/(1+x^2), -1.2,1.2)585960