|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
/*
* This file:
* http://anggtwu.net/MAXIMA/2025-1-taylor.mac.html
* http://anggtwu.net/MAXIMA/2025-1-taylor.mac
* (find-angg "MAXIMA/2025-1-taylor.mac")
* Author: Eduardo Ochs <eduardoochs@gmail.com>
*
* (defun e () (interactive) (find-angg "MAXIMA/2025-1-taylor.mac"))
* (find-angg "MAXIMA/mkmatrix1.mac")
* (find-angg "MAXIMA/2025-methods.mac")
* (find-es "maxima" "2024.1-taylor-1")
*
* «.f_x» (to "f_x")
* «.polys» (to "polys")
* «.cis» (to "cis")
* «.MatrixL» (to "MatrixL")
* «.MatrixL-tests» (to "MatrixL-tests")
* «.Taylor2» (to "Taylor2")
* «.Taylor2-tests» (to "Taylor2-tests")
*/
load("~/MAXIMA/mkmatrix1.mac");
load("~/MAXIMA/2025-methods.mac");
defstruct(Taylor(f,var,x0,maxk));
Taylor__aa__(T,k) := diff(T@f, T@var, k);
Taylor__bb__(T,k) := at(diff(T@f, T@var, k), [T@var=T@x0]);
Taylor__cc__(T,k) := at(diff(T@f, T@var, k), [T@var=T@x0]) / k!;
Taylor__dd__(T,k,x) := at(diff(T@f, T@var, k), [T@var=T@x0]) / k! * (x-T@x0)^k;
Taylor__aa (T) := mkvmatrix([k,0,T@maxk], T@@aa__(k));
Taylor__bb (T) := mkvmatrix([k,0,T@maxk], T@@bb__(k));
Taylor__cc (T) := mkvmatrix([k,0,T@maxk], T@@cc__(k));
Taylor__dd (T,xx) := mkvmatrix([k,0,T@maxk], T@@dd__(k,xx));
Taylor__abcd(T,xx) := [T@@aa(), T@@bb(), T@@cc(), T@@dd(xx)];
Taylor__s (T,xx) := sum(T@@dd__(k,xx), k,0,T@maxk);
/* «f_x» (to ".f_x")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("2025-1-taylor.mac")$
gradef(f (x), f_x (x))$
gradef(f_x (x), f_xx (x))$
gradef(f_xx (x), f_xxx (x))$
gradef(f_xxx (x), f_xxxx (x))$
gradef(f_xxxx(x), f_xxxxx(x))$
myt : Taylor(f(x),x,0,4);
myt@@abcd(x);
myt@@s(x);
myt@@s(a);
myt@@s(1/10);
*/
/* «polys» (to ".polys")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("2025-1-taylor.mac");
f3(x) := a + b*x + c*x^2 + d*x^3;
myt : Taylor(f3(x),x,0,4)$
myt@@abcd(x);
myt@@s(x);
f4(x) := a + b*x + c*x^2 + d*x^3 + e*x^4;
myt : Taylor(f4(x),x,0,4)$
myt@@abcd(x);
myt@@s(x);
f5(x) := a + b*x + c*x^2 + d*x^3 + e*x^4 + f*x^5;
myt : Taylor(f5(x),x,0,4)$
myt@@abcd(x);
myt@@s(x);
*/
/* «cis» (to ".cis")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
texput("th", "\\theta ");
load("2025-1-taylor.mac");
myte : Taylor(exp( th) , th,0,5)$
myte2 : Taylor(exp( 2*th) , th,0,5)$
mytei : Taylor(exp(%i*th) , th,0,5)$
mytc : Taylor(cos(th) , th,0,5)$
myts : Taylor( sin(th), th,0,5)$
mytis : Taylor( %i*sin(th), th,0,5)$
mytcis : Taylor(cos(th)+%i*sin(th), th,0,5)$
myte @@abcd(th);
myte2 @@abcd(th);
mytei @@abcd(th);
mytc @@abcd(th);
myts @@abcd(th);
mytis @@abcd(th);
mytcis@@abcd(th);
mytei @@s(th);
mytcis@@s(th);
*/
/* «MatrixL» (to ".MatrixL")
*/
defstruct(MatrixL(o));
MatrixL__ht (ml) := length(ml@o);
MatrixL__maxwd (ml) := apply('max, map('length, ml@o));
MatrixL__padrow(ml,row) := append(row, makelist("", ml@@maxwd()-length(row)));
MatrixL__padded(ml) := makelist(ml@@padrow(ml@o[i]), i,1,ml@@ht());
MatrixL__matrix(ml) := apply('matrix, ml@@padded());
mkmatrixL__(N,ex) := buildq([N,ex],
makelist(create_list(ev(ex), yn,seq(0,dg), xn,[dg-yn]), dg,0,N));
mkmatrixL_(N,ex) ::= mkmatrixL__(N,ex);
mkmatrixL (N,ex) ::= MatrixL(mkmatrixL_(N,ex))@@matrix();
mklistL_(N,ex) := buildq([N,ex],
create_list(ev(ex), dg,seq(0,N), yn,seq(0,dg), xn,[dg-yn]));
mklistL (N,ex) ::= mklistL_(N,ex);
/* (find-es "maxima" "create_list")
*/
/* «MatrixL-tests» (to ".MatrixL-tests")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("2025-1-taylor.mac");
mym : MatrixL([[a], [b,c], [d,e,f,g]]);
mym@@padrow([2,3]);
mym@@padded();
mym@@matrix();
mkmatrixL__(2,[dg,xn,yn]);
mkmatrixL_ (2,[dg,xn,yn]);
mkmatrixL (2,[dg,xn,yn]);
mklistL_ (2,[dg,xn,yn]);
mklistL (2,[dg,xn,yn]);
depends(z,[x,y]);
derivabbrev : true;
mkmatrixL(2,diff(z,x,xn,y,yn));
diff(z,x,2,y,3);
myd : makelist(makelist([yn,dg] ,yn,0,dg), dg,0,2);
myd : makelist(makelist(diff(z,x,dg-yn,y,yn) ,yn,0,dg), dg,0,2);
MatrixL(myd)@@matrix();
*/
/* «Taylor2» (to ".Taylor2")
*/
defstruct(Taylor2(f,x0,y0,maxdg));
Taylor2__aa__(T,xn,yn) := diff(T@f, x,xn, y,yn);
Taylor2__bb__(T,xn,yn) := at(diff(T@f, x,xn, y,yn), [x=T@x0, y=T@y0]);
Taylor2__cc__(T,xn,yn) := at(diff(T@f, x,xn, y,yn), [x=T@x0, y=T@y0]) / (xn!*yn!);
Taylor2__dd__(T,xn,yn,xx,yy) := at(diff(T@f, x,xn, y,yn), [x=T@x0, y=T@y0]) / (xn!*yn!)
* (xx-T@x0)^xn * (yy-T@y0)^yn;
Taylor2__aa (T) := mkmatrixL(T@maxdg, T@@aa__(xn,yn));
Taylor2__bb (T) := mkmatrixL(T@maxdg, T@@bb__(xn,yn));
Taylor2__cc (T) := mkmatrixL(T@maxdg, T@@cc__(xn,yn));
Taylor2__dd (T,xx,yy) := mkmatrixL(T@maxdg, T@@dd__(xn,yn,xx,yy));
Taylor2__dd_ (T,xx,yy) := mklistL (T@maxdg, T@@dd__(xn,yn,xx,yy));
Taylor2__abcd(T,xx,yy) := [T@@aa(), T@@bb(), T@@cc(), T@@dd(xx,yy)];
Taylor2__s (T,xx,yy) := apply("+", T@@dd_(xx,yy));
/* «Taylor2-tests» (to ".Taylor2-tests")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("2025-1-taylor.mac");
depends(z,[x,y]);
derivabbrev : true;
myt : Taylor2(z ,0,0,2);
myt : Taylor2(2+x^2+y^2,0,0,2);
myt@@aa();
myt@@abcd(x,y);
myt@@s (x,y);
*/
/*
* Local Variables:
* coding: utf-8-unix
* End:
*/