When you start wxMaxima, a window will apear with content similar to
wxMaxima 0.3 http://www.geocities.com/avodopivec Maxima 5.9.1 http://maxima.sourceforge.net Using Lisp CMU Common Lisp 19a fedora release 0.fdr.2.a.1 Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. This is a development version of Maxima. The function bug_report() provides bug reporting information. (%i1)in the main area. This is where maxima output is displayed. User enters input in the input line below the display area.
The (%i1) is a ``label''. Each input or output line is labelled and can be referred to by its own label for the rest of the session. %i labels denote your commands and %o labels denote Displays of the machine's response. Never use variable names like %i1 or %o5, as these will be confused with the lines so labeled.
MAXIMA is pragmatic about lower and upper case: regardless of your typing sin(x) or SIN(x), %e^x or %E^x, it will understand that you mean the sine and exponential functions, and will echo in standard uppercase SIN and %E. That doesn't apply to user variables, though: x and X are different variables for MAXIMA ! (Try it.)
(%i1) quit(); CLIENT: Lost socket connection ... Restart maxima with maxima->restart.You can restart maxima by selecting Maxima->Restart from menus.
(%i1) sum(1/x^2, x, 1, 10000); Maxima encountered a Lisp error: Interrupted at #x1135634A. Automatically continuing. To reenable the Lisp debugger set *debugger-hook* to nil. (%i2)
The common arithmetic operations are
MAXIMA's output is characterized by exact (rational) arithmetic. E.g.,
(%i1) 1/100+1/101; 201 (%o1) ----- 10100If irrational numbers are involved in a computation, they are kept in symbolic form:
(%i2) (1+sqrt(2))^5; 5 (%o2) (SQRT(2) + 1) (%i3) expand(%); (%o3) 29 SQRT(2) + 41However, it is often useful to express a result in decimal notation. This may be accomplished by following the expression you want expanded by ``,numer'':
(%i4) %,numer; (%o4) 82.01219330881976Note the use here of % to refer to the previous result. In this version of MAXIMA, numer gives 16 significant figures, of which the last is often unreliable. However, MAXIMA can offer arbitrarily high precision by using the bfloat function:
(%i5) bfloat(d3); (%o5) 8.201219330881976B1The number of significant figures displayed is controlled by the MAXIMA variable FPPREC, which has the default value of 16:
(%i6) fpprec; (%o6) 16Here we reset FPPREC to yield 100 digits:
(%i7) fpprec:100; (%o7) 100 (%i8) ''%i5; (%o8) 8.20121933088197564152489730020812442785204843859314941221237124017312418# 7540110412666123849550160561B1Note the use of two single quotes ('') in (%i8) to repeat command (%i5). MAXIMA can handle very large numbers without approximation:
(%i9) 100!; (%o9) 9332621544394415268169923885626670049071596826438162146859296389521759999# 322991560894146397615651828625369792082722375825118521091686400000000000000000# 0000000
MAXIMA's importance as a computer tool to facilitate analytical calculations becomes more evident when we see how easily it does algebra for us. Here's an example in which a polynomial is expanded:
(%i1) (x+3*y+x^2*y)^3; 2 3 (%o1) (x y + 3 y + x) (%i2) expand(%); 6 3 4 3 2 3 3 5 2 3 2 2 4 (%o2) x y + 9 x y + 27 x y + 27 y + 3 x y + 18 x y + 27 x y + 3 x y 2 3 + 9 x y + xNow suppose we wanted to substitute 5/z for x in the above expression:
(%i3) %o2,x=5/z; 2 3 2 3 2 135 y 675 y 225 y 2250 y 125 5625 y 1875 y 9375 y (%o3) ------ + ------ + ----- + ------- + --- + ------- + ------ + ------- z 2 2 3 3 4 4 5 z z z z z z z 3 15625 y 3 + -------- + 27 y 6 zThe MAXIMA function RATSIMP will place this over a common denominator:
(%i4) ratsimp(%); 3 6 2 5 3 4 2 3 (%o4) (27 y z + 135 y z + (675 y + 225 y) z + (2250 y + 125) z 3 2 2 3 6 + (5625 y + 1875 y) z + 9375 y z + 15625 y )/zExpressions may also be factored:
(%i5) factor(%); 2 3 (3 y z + 5 z + 25 y) (%o5) ---------------------- 6 zMAXIMA can obtain exact solutions to systems of nonlinear algebraic equations. In this example we solve three equations in the three unknowns A, B, C:
(%i6) a + b*c=1; (%o6) b c + a = 1 (%i7) b - a*c=0; (%o7) b - a c = 0 (%i8) a+b=5; (%o8) b + a = 5 (%i9) solve([%o6,%o7,%o8],[a,b,c]); 25 SQRT(79) %I + 25 5 SQRT(79) %I + 5 SQRT(79) %I + 1 (%o9)[[a = -------------------, b = -----------------, c = ---------------], 6 SQRT(79) %I - 34 SQRT(79) %I + 11 10 25 SQRT(79) %I - 25 5 SQRT(79) %I - 5 SQRT(79) %I - 1 [a = -------------------, b = -----------------, c = - ---------------]] 6 SQRT(79) %I + 34 SQRT(79) %I - 11 10Note that the display consists of a ``list'', i.e., some expression contained between two brackets [ ... ], which itself contains two lists. Each of the latter contain a distinct solution to the simultaneous equations.
Trigonometric identities are easy to manipulate in MAXIMA. The function trigexpand uses the sum-of-angles formulas to make the argument inside each trig function as simple as possible:
(%i10) sin(u+v)*cos(u)^3; 3 (%o10) COS (u) SIN(v + u) (%i11) trigexpand(%); 3 (%o11) COS (u) (COS(u) SIN(v) + SIN(u) COS(v))The function trigreduce, on the other hand, converts an expression into a form which is a sum of terms, each of which contains only a single sin or cos:
(%i12) trigreduce(d10); SIN(v + 4 u) + SIN(v - 2 u) 3 SIN(v + 2 u) + 3 SIN(v) (%o12) --------------------------- + ------------------------- 8 8The functions realpart and imagpart will return the real and imaginary parts of a complex expression:
(%i13) w:3+k*%i; (%o13) %I k + 3 (%i14) w^2*%e^w; 2 %I k + 3 (%o14) (%I k + 3) %E (%i15) realpart(%); 3 2 3 (%o15) %E (9 - k ) COS(k) - 6 %E k SIN(k)
MAXIMA can compute derivatives and integrals, expand in Taylor series, take limits, and obtain exact solutions to ordinary differential equations. We begin by defining the symbol f to be the following function of x:
(%i1) f:x^3*%E^(k*x)*sin(w*x); 3 k x (%o1) x %E SIN(w x)We compute the derivative of f with respect to x:
(%i2) diff(f,x); 3 k x 2 k x 3 k x (%o2) k x %E SIN(w x) + 3 x %E SIN(w x) + w x %E COS(w x)Now we find the indefinite integral of f with respect to x:
(%i3) integrate(f,x); 6 3 4 5 2 7 3 (%o3) (((k w + 3 k w + 3 k w + k ) x 6 2 4 4 2 6 2 4 3 2 5 + (3 w + 3 k w - 3 k w - 3 k ) x + (- 18 k w - 12 k w + 6 k ) x 4 2 2 4 k x - 6 w + 36 k w - 6 k ) %E SIN(w x) 7 2 5 4 3 6 3 5 3 3 5 2 + ((- w - 3 k w - 3 k w - k w) x + (6 k w + 12 k w + 6 k w) x 5 2 3 4 3 3 k x + (6 w - 12 k w - 18 k w) x - 24 k w + 24 k w) %E COS(w x)) 8 2 6 4 4 6 2 8 /(w + 4 k w + 6 k w + 4 k w + k )A slight change in syntax gives definite integrals:
(%i4) integrate(1/x^2,x,1,inf); (%o4) 1 (%i5) integrate(1/x,x,0,inf); Integral is divergent -- an error. Quitting. To debug this try DEBUGMODE(TRUE);)Next we define the simbol g in terms of f (previously defined in %i1) and the hyperbolic sine function, and find its Taylor series expansion (up to, say, order 3 terms) about the point x = 0:
(%i6) g:f/sinh(k*x)^4; 3 k x x %E SIN(w x) (%o6) ----------------- 4 SINH (k x) (%i7) taylor(g,x,0,3); 2 3 2 2 3 3 w w x (w k + w ) x (3 w k + w ) x (%o7)/T/ -- + --- - -------------- - ---------------- + . . . 4 3 4 3 k k 6 k 6 k |
(%i8) limit(g,x,0); w (%o8) -- 4 kMAXIMA also permits derivatives to be represented in unevaluated form (note the quote):
(%i9) 'diff(y,x); dy (%o9) -- dxThe quote operator in (%i9) means ``do not evaluate''. Without it, MAXIMA would have obtained 0:
(%i10) diff(y,x); (%o10) 0Using the quote operator we can write differential equations:
(%i11) 'diff(y,x,2) + 'diff(y,x) + y; 2 d y dy (%o11) --- + -- + y 2 dx dxMAXIMA's ODE2 function can solve first and second order ODE's:
(%i12) ode2(%o11,y,x); - x/2 SQRT(3) x SQRT(3) x (%o12) y = %E (%K1 SIN(---------) + %K2 COS(---------)) 2 2
MAXIMA can compute the determinant, inverse and eigenvalues and eigenvectors of matrices which have symbolic elements (i.e., elements which involve algebraic variables.) We begin by entering a matrix m element by element:
(%i1) m:entermatrix(3,3); Is the matrix 1. Diagonal 2. Symmetric 3. Antisymmetric 4. General Answer 1, 2, 3 or 4 : 4; Row 1 Column 1: 0; Row 1 Column 2: 1; Row 1 Column 3: a; Row 2 Column 1: 1; Row 2 Column 2: 0; Row 2 Column 3: 1; Row 3 Column 1: 1; Row 3 Column 2: 1; Row 3 Column 3: 0; Matrix entered. [ 0 1 a ] [ ] (%o1) [ 1 0 1 ] [ ] [ 1 1 0 ]You can also input matrices using a dialog by selecting Algebra->Enter matrix. Next we find its transpose, determinant and inverse:
(%i2) transpose(m); [ 0 1 1 ] [ ] (%o2) [ 1 0 1 ] [ ] [ a 1 0 ] (%i3) determinant(m); (%o3) a + 1 (%i4) invert(m),detout; [ - 1 a 1 ] [ ] [ 1 - a a ] [ ] [ 1 1 - 1 ] (%o4) ----------------- a + 1In (%i4), the modifier DETOUT keeps the determinant outside the inverse. As a check, we multiply m by its inverse (note the use of the period to represent matrix multiplication):
(%i5) m.%o4; [ - 1 a 1 ] [ ] [ 1 - a a ] [ 0 1 a ] [ ] [ ] [ 1 1 - 1 ] (%o5) [ 1 0 1 ] . ----------------- [ ] a + 1 [ 1 1 0 ] (%i6) expand(%); [ a 1 ] [ ----- + ----- 0 0 ] [ a + 1 a + 1 ] [ ] [ a 1 ] (%o6) [ 0 ----- + ----- 0 ] [ a + 1 a + 1 ] [ ] [ a 1 ] [ 0 0 ----- + ----- ] [ a + 1 a + 1 ] (%i7) factor(%); [ 1 0 0 ] [ ] (%o7) [ 0 1 0 ] [ ] [ 0 0 1 ]In order to find the eigenvalues and eigenvectors of m, we use the function EIGENVECTORS:
(%i8) eigenvectors(m); Warning - you are redefining the MACSYMA function EIGENVALUES Warning - you are redefining the MACSYMA function EIGENVECTORS SQRT(4 a + 5) - 1 SQRT(4 a + 5) + 1 (%o8) [[[- -----------------, -----------------, - 1], [1, 1, 1]], 2 2 SQRT(4 a + 5) - 1 SQRT(4 a + 5) - 1 [1, - -----------------, - -----------------], 2 a + 2 2 a + 2 SQRT(4 a + 5) + 1 SQRT(4 a + 5) + 1 [1, -----------------, -----------------], [1, - 1, 0]] 2 a + 2 2 a + 2In %o8, the first triple gives the eigenvalues of m and the next gives their respective multiplicities (here each is unrepeated). The next three triples give the corresponding eigenvectors of m. In order to extract from this expression one of these eigenvectors, we may use the PART function:
(%i9) part(%,2); SQRT(4 a + 5) - 1 SQRT(4 a + 5) - 1 (%o9) [1, - -----------------, - -----------------] 2 a + 2 2 a + 2
So far, we have used MAXIMA in the interactive mode, rather like a calculator. However, for computations which involve a repetitive sequence of commands, it is better to execute a program. Here we present a short sample program to calculate the critical points of a function f of two variables x and y. The program cues the user to enter the function f, then it computes the partial derivatives fx and fy, and then it uses the MAXIMA command SOLVE to obtain solutions to fx = fy = 0. The program is written outside of MAXIMA with a text editor, and then loaded into MAXIMA with the BATCH command. Here is the program listing:
/* -------------------------------------------------------------------------- this is file critpts.max: as you can see, comments in maxima are like comments in C Nelson Luis Dias, nldias@simepar.br created 20000707 updated 20000707 --------------------------------------------------------------------------- */ critpts():=( print("program to find critical points"), /* --------------------------------------------------------------------------- asks for a function --------------------------------------------------------------------------- */ f:read("enter f(x,y)"), /* --------------------------------------------------------------------------- echoes it, to make sure --------------------------------------------------------------------------- */ print("f = ",f), /* --------------------------------------------------------------------------- produces a list with the two partial derivatives of f --------------------------------------------------------------------------- */ eqs:[diff(f,x),diff(f,y)], /* --------------------------------------------------------------------------- produces a list of unknowns --------------------------------------------------------------------------- */ unk:[x,y], /* --------------------------------------------------------------------------- solves the system --------------------------------------------------------------------------- */ solve(eqs,unk) )$The program (which is actually a function with no argument) is called critpts. Each line is a valid MAXIMA command which could be executed from the keyboard, and which is separated by the next command by a comma. The partial derivatives are stored in a variable named eqs, and the unknowns are stored in unk. Here is a sample run:
(%i1) batch("critpts.max"); batching #/home/nldias/work/papers2000/intromax/critpts.max (%i2) (%i2) critpts() := (PRINT("program to find critical points"), f : READ("enter f(x,y)"), PRINT("f = ", f), eqs : [DIFF(f, x), DIFF(f, y)], unk : [x, y], SOLVE(eqs, unk)) (%i3) critpts(); program to find critical points enter f(x,y) %e^(x^3+y^2)*(x+y); 2 3 y + x f = (y + x) %E (%o3) [[x = 0.4588955685487 %I + 0.35897908710869, y = 0.49420173682751 %I - 0.12257873677837], [x = 0.35897908710869 - 0.4588955685487 %I, y = - 0.49420173682751 %I - 0.12257873677837], [x = 0.41875423272348 %I - 0.69231242044203, y = 0.4559120701117 - 0.86972626928141 %I], [x = - 0.41875423272348 %I - 0.69231242044203, y = 0.86972626928141 %I + 0.4559120701117]]
(%i1) plot2d([sin(x), cos(x)], [x,-%pi,3*%pi], [gnuplot_preamble, "set zeroaxis"])$ (%i2) plot3d(x^2-y^2, [x,-5,5], [y,-5,5], [gnuplot_pm3d, true])$ (%i3) plot2d([[parametric, cos(3*t), sin(5*t), [t, 0, 2*%pi]]], [x,-5,5], [nticks,200])$ (%i4) plot2d([2+cos(3*ph)], [ph,0,2*%pi], [gnuplot_preamble, "set polar; set zeroaxis"])$
For more maxima commands see the Maxima Manual section of help. From MAXIMA itself, you can use DESCRIBE(functionname).
1 Adapted from ``Perturbation Methods, Bifurcation Theory and Computer Algebra'' by Rand and Armbruster, Springer, 1987
2 Adapted to LATEX and HTML by Nelson L. Dias (nldias@simepar.br), SIMEPAR Technological Institute and Federal University of Paranį, Brazil
Further adapted for wxMaxima by Andrej Vodopivec.