Annotation of OpenXM_contrib/pari-2.2/examples/taylor.gp, Revision 1.1
1.1 ! noro 1: \\ originally contributed by Ilya Zakharevich
! 2:
! 3: \\ sample function
! 4: f(x) = sin(x)
! 5:
! 6: \\ plot Taylor polynomials of f of index first + i*step <= ordlim
! 7: \\ for x in [xmin,xmax].
! 8: plot_taylor(xmin=-5, xmax=5, ordlim=16, first=1, step=1) =
! 9: {
! 10: local(T,Taylor_array,s,t,w,h,dw,dh,cw,ch,gh,h1, extrasize = 0.6);
! 11:
! 12: default(seriesprecision,ordlim+1);
! 13: ordlim -= first; ordlim \= step; ordlim += first;
! 14: T = f(tt); Taylor_array = vector(ordlim+1);
! 15: forstep(i=ordlim+1, 1, -1,
! 16: T += O(tt^(1 + first + (i-1)*step));
! 17: Taylor_array[i] = truncate(T)
! 18: );
! 19:
! 20: t = plothsizes();
! 21: w=floor(t[1]*0.9)-2; dw=floor(t[1]*0.05)+1; cw=t[5];
! 22: h=floor(t[2]*0.9)-2; dh=floor(t[2]*0.05)+1; ch=t[6];
! 23: h1=floor(h/1.2);
! 24:
! 25: plotinit(2, w+2*dw, h+2*dh);
! 26: plotinit(3, w, h1);
! 27: s = plotrecth(3, x=xmin,xmax, f(x), 2+8+16+32);
! 28: gh=s[4]-s[3];
! 29:
! 30: plotinit(3, w, h);
! 31: plotscale(3,s[1],s[2],s[3]-gh*extrasize/2,s[4]+gh*extrasize/2);
! 32: plotrecth(3, x=xmin,xmax,
! 33: concat(f(x), subst(Taylor_array, tt, x)), 4);
! 34: plotclip(3);
! 35: plotcopy(3, 2, dw, dh);
! 36:
! 37: plotmove(2,floor(dw+w/2-15*cw),floor(dh/2));
! 38: plotstring(2,"Multiple Taylor Approximations");
! 39: plotdraw([2, 0, 0])
! 40: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>