NOTES ON MAXIMA Webpage: http://maxima.sourceforge.net/ Free, open source software, released under GPL. The Windows download is very easy. The Linux download is slightly more complicated; the most recent binary requires a somewhat obsolete system library (readline), but it works if you just copy the library and put it in the library path. Tutorials: * R Dodier, "Minimal Maxima", http://maxima.sourceforge.net/docs/tutorial/en/minimal-maxima.pdf (primary source for these notes) * R Rand, "Introduction to Maxima", http://maxima.sourceforge.net/docs/intromax/intromax.pdf Maxima is a computer algebra system which is designed for symbolic manipulation rather than for numbers. It's based on one of the original computer algebra systems (Macsyma), developed at MIT in the 1960's. Remember when I said last term that computers are good for mechanical and repetitive operations! Algebra is that way to some extent, but not all - and we'll see examples of how computers can also be really stupid. Since it was originally developed even before anything like C existed, it's not surprising that the syntax doesn't resemble it much. Some have complained that it's a rather difficult syntax, and indeed it's perhaps less obvious than Maple or Mathematica, but I think it's just different, and makes sense in its own way. Again, just like C or Matlab, the learning is really in the playing. I will go through some of the basics using wxMaxima, the Windows interface (which is reasonably nice). Then we'll derive some expressions for numerical integration which are rather tedious to do - perfect for a computer algebra system! BASIC CALCULATIONS V : 4/3 * %pi * r^3; assignment of an *expression* to a symbol r : 10 $ don't print out result V; ''V; evaluate V in light of r assignment ''V, numer; some setup in wxMaxima: Edit->Configure->Style->use greek font bfloat(%o..); (point to output of ''V;) fpprec:32; bfloat(%o..); ''V, bfloat; alternative formulation of an operation kill(all); clear everything quit(); exits when purely command-line EXPRESSIONS everything is an expression atom: a symbol, a string, or a number all non-atoms: op(a1, a2, a3, ...) op: an operator, function, etc. (also implements programming constructs) a1: arguments program flow: if a then b elseif c then d -> if(a,b,c,d) for a in L do S -> do(a,L,S) [ a, foo, foo_bar, "Hello", 42, 17.29 ]; atoms [ a + b + c, a * b * c, foo = bar, a*b < c*d ]; math [ a, b, c, %pi, %e, 1729, 1/(a*d - b*c) ]; L[7]; M: matrix([%pi, 17], [29, %e]); M2: matrix( [[%pi, 17], a*d-b*c], [ matrix([1,a],[b,7]), %e] ); M[2][1]; M2[2][1]; (a:42) - (b:17); [a,b]; block([a], a:42, a^2 - 1600) + block([b], b:5, %pi^b); (if a>1 then %pi else %e) + (if b<0 then 1/2 else 1/7); block( a:1, b:%pi, c:x+y); [a,b,c]; kill(a,b,c); how to delete a symbol definition [a,b,c]; now just evaluate to themselves foo(p,q) := p - q; function definition p:%phi; all symbols global by default - can cause odd problems when past definitions impinge on current work foo(p,q); bar(p,q); undefined (or just deferred!) block( a:%e, b:17 ); foo(a,b); foo('a,'b); prevents evaluation of a and b 'foo(a,b); '(foo(a,b)); diff(sin(x),x); differentiation foo(x) := diff(sin(x),x); doesn't evaluate if defining a function foo(x) := ''diff(sin(x),x); forced to evaluate in function definition There are subtleties in evaluation which I won't go into here. It's much better to work through some examples (such as in the tutorials) to get an idea of the how and why, otherwise it just seems random. SIMPLIFICATION Only the most obvious simplifications are applied, such as 1+1 -> 2. Otherwise, notice that simplifications are often rather artfully done, so instead of second-guessing you, Maxima allows you to apply simplifications explicitly. (a+b)^2; expand(%); factor(%); a/b + c/b; ratsimp(%); sin(2*x); trigexpand(%); trigreduce(%); a*exp(b*%i); demoivre(%); SOLVING EQUATIONS eq_1 : a*x + b*y + z = %pi; eq_2 : z - 5*y + x = 0; s: solve( [eq_1, eq_2], [x, z] ); length(s); [subst(s[1], eq_1), subst(s[1], eq_2)]; substituting equations ratsimp(%); CALCULUS integrate( 1/(1+x), x, 0, 1); definite integration integrate( exp(-u)*sin(u), u, 0, inf); diff(sin(y*x)); diff(sin(y*x),x); diff(sin(y*x),y); diff(sin(y*x), x, 2); 'diff(sin(y*x), x, 2); ORDINARY DIFFERENTIAL EQUATIONS oeq : 'diff(y,x,2) + 'diff(y,x) + y; note ' to prevent eval if not, diff(y,x) gives 0! s : ode2(oeq, y, x); homogeneous ODE yy : args(s)[2]; extract the formula part diff(yy,x,2) + diff(yy,x) + yy; confirm that it's correct ratsimp(%); OTHER THINGS THAT MAXIMA CAN DO matrices and linear algebra, including finding eigenvalues/vectors. tensors. sums. sets, groups, symmetries, number theory. PLOTS plot2d( exp(-u)*sin(u), [u, 0, 2*%pi] ); plot2d( [exp(-u), exp(-u)*sin(u)], [u, 0, 2*%pi] ); There are also 3d plots NUMERICAL INTEGRATION (QUADRATURE) Derive closed Newton-Cotes formulae using Maxima (Simpson's Rule). The basic idea is that if you have a function evaluated at several equally spaced points (in this case), you can "approximate" the function with an interpolating polynomial which is easy (but tedious) to integrate. kill(all); simp:true$ p : [ [x[0],y[0]], [x[1],y[1]], [x[2],y[2]] ]; x[1] : x[0] + h; x[2] : x[1] + h; equally spaced points p; ''p; this evaluates p, substituting in x[1] etc load(interpol); fundef(lagrange); lp : lagrange(p); still has x[1], x[2] lp2 : ratsimp(lp); ''lp2; do substitutions ilp : integrate(%,x); x : x[2]; upper : ''ilp; x : x[0]; lower : ''ilp; upper - lower; ratsimp(%); sometimes evaluations will seem a bit counterintuitive because the internal form of the stored expression isn't so easy to see! General Newton-Cotes script try loading this without kill(all) to clean up first. Maxima will probably substitute directly into the script. fundef(newtoncotes); newtoncotes(2); bleah! newtoncotes(n) := ( local(p,i,z0,lp,df), p:[], for i:0 thru n do p:append(p,[ [z0+i*h,y[i]] ]), lp : ratsimp(lagrange(p)), df : integrate(''lp, x, z0, z0+n*h), factor(ratsimp(df)) ); load("/newtoncotes"); fundef(newtoncotes); newtoncotes(2); newtoncotes(3); Simpson's 3/8 rule newtoncotes(4); another common one (Booles?)