Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
/* This file: * http://anggtwu.net/MAXIMA/pn1.mac.html * http://anggtwu.net/MAXIMA/pn1.mac * (find-angg "MAXIMA/pn1.mac") * Author: Eduardo Ochs <eduardoochs@gmail.com> * * Some support for "physicist's notation". * See: (find-es "maxima" "total-derivative") * (find-es "maxima" "implicit-diff") * http://anggtwu.net/eev-maxima.html#physicists-notation * * (defun e () (interactive) (find-angg "MAXIMA/pn1.mac")) * * «.basic-tests» (to "basic-tests") * «.folium-depvars» (to "folium-depvars") * «.folium-depvars-and-ds» (to "folium-depvars-and-ds") * «.partial-and-total» (to "partial-and-total") */ pnshorten_del(delx) := buildq([delx, dx:concat('d,args(delx)[1])], delx=dx)$ pnexpand_del (delx) := buildq([delx, dx:concat('d,args(delx)[1])], dx=delx)$ pnshorten_f (zxyz) := buildq([ z : op (lhs(zxyz)), xy : args(lhs(zxyz))], z(splice(xy)) = z)$ pnexpand_f (zxyz) := buildq([ z : op (lhs(zxyz)), xy : args(lhs(zxyz))], z = z(splice(xy)))$ pnshorten_1 (pexpr) := if is(op(pexpr)='del) then pnshorten_del(pexpr) else pnshorten_f(pexpr)$ pnexpand_1 (pexpr) := if is(op(pexpr)='del) then pnexpand_del(pexpr) else pnexpand_f(pexpr)$ pnshorten_ify(pexprs) := map('pnshorten_1,pexprs); pnexpand_ify (pexprs) := map('pnexpand_1, pexprs); pnshorten (pexprs,o) := subst(pnshorten_ify(pexprs), o); pnexpand (pexprs,o) := subst(pnexpand_ify (pexprs), o); pnshortenr(pexprs,o) := subst(reverse(pnshorten_ify(pexprs)), o); pnexpandr (pexprs,o) := subst(reverse(pnexpand_ify (pexprs)), o); pnas : [y(x),y_x(x),del(x),del(y)]; /* Default abbreviations! Change this! */ pnex(o) := pnexpand (pnas, o); /* Expand using the current pnas */ pnsh(o) := pnshortenr(pnas, o); /* Shorten using the current pnas */ /* * «basic-tests» (to ".basic-tests") * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("~/MAXIMA/pn1.mac"); pnas : [y(x),del(x)]; pnashorten_ify(pnas); pnexpand_ify (pnas); pnshorten (pnas, (y(x1)-y(x))/del(x)); pnexpand (pnas, y *dx); pnexpand (pnas, (y(x1)-y)*dx); "doesn't work"$ */ /* * «folium-depvars» (to ".folium-depvars") * The Folium of Descartes is: * x^3 + y^3 = 6*x*y; * In this test we differentiate the Folium implicitly * using only dependent variables. * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("~/MAXIMA/pn1.mac"); gradef(y(x), y_x(x)); "these tests don't use gradef(y,x,y_x)"$ e1 : x^3 + y^3 = 6*x*y; "Folium of Descartes"$ pnex(e1); diff(pnex(e1), x); e2 : pnsh(diff(pnex(e1), x)); e3 : solve(e2, y_x)[1]; */ /* * «folium-depvars-and-ds» (to ".folium-depvars-and-ds") * In this variant we differentiate the Folium * using dependent variables and differentials. * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("pn1.mac"); gradef(y(x), y_x(x)); "these tests don't use gradef(y,x,y_x)"$ e1 : x^3 + y^3 = 6*x*y; "Folium of Descartes"$ diff(e1); e2 : pnsh(diff(e1)); solve(e2, dy)[1]; factor(solve(e2, dy)[1]); e3 : factor(solve(e2, dy)[1]) / dx; */ /* * «partial-and-total» (to ".partial-and-total") * If z=z(x,y) and y=y(x) then we have this: * ∂/∂x z = d/dx z(x,y) = z_x * d/dx z = d/dx z(x,y(x)) = z_x + z_y y_x * i.e., the "partial derivative" ∂/∂x z * and the "total derivative" d/dx z * are different... * (eepitch-maxima) * (eepitch-kill) * (eepitch-maxima) load("pn1.mac"); "Use z=z(x,y) and y=y(x)"$ map('kill, [z,y]); gradef(z(x,y), z_x(x,y), z_y(x,y)); gradef(y(x), y_x(x)); gradefs; pnas : [z(x,y),z_x(x,y),z_y(x,y), y(x),y_x(x)]; pnex(z); diff(pnex(z),x); pnsh(diff(pnex(z),x)); "=> z_x + z_y y_x"$ "Use only z=z(x,y)"$ map('kill, [z,y]); gradef(z(x,y), z_x(x,y), z_y(x,y)); gradefs; pnas : [z(x,y),z_x(x,y),z_y(x,y)]; pnex(z); diff(pnex(z),x); pnsh(diff(pnex(z),x)); "=> z_x"$ */