Maxima is a nice computer algebra system, however, the docs are rather hard to read.
A distinct feature of maxima is that each command must end ended with a semicolon. The command is not reacted upon until one enters the semicolon, it feels as if maxima is not working while in fact it is just waiting for the semincolon, possibly on a new line.
The help can be accessed with
? <topic>
Note space between ?
and the topic, also semicolon is not needed. Topics can be function names.
Variables can be assigned as variable : expression
. For instance,
## (%i1) x:1
## (%o1) 1
## (%i2) q:1-p
## (%o2) 1 - p
Variables can be removed with kill
function:
## (%i1) x:1
## (%o1) 1
## (%i2) x
## (%o2) 1
## (%i3) kill(x)
## (%o3) done
## (%i4) x
## (%o4) x
Functions can be defined with :=
, and called with just the name afterwards:
## (%i1) f(x,y):=x^2-y^2
## 2 2
## (%o1) f(x, y) := x - y
## (%i2) f(1,2)
## (%o2) - 3
Function bodies can contain multiple expressions, these should be separated by ,
(not by semicolon), potentially as the last character on a line. If the function body contains multiple lines, these should be enclosed in parenthesis. So we can define a function like
## (%i1) r(x,y):=(x2:x^2,y2:y^2,(x2+y2)^0.5)
## 2 2 0.5
## (%o1) r(x, y) := (x2 : x , y2 : y , (x2 + y2) )
## (%i2) r(1,1)
## (%o2) 1.414213562373095
expand
opens parenthesis and collects the relevant items:
## (%i1) e:(a+b)*(a-b)
## (%o1) (a - b) (b + a)
## (%i2) expand(e)
## 2 2
## (%o2) a - b
ratsimp
attempts to simplify the expression into fractions of polynomials, including inside of non-rational functions.
## (%i1) e:a^2-b^2
## 2 2
## (%o1) a - b
## (%i2) ratsimp(e)
## 2 2
## (%o2) a - b
express
evaluates unevaluated expression
solve
can solve non-linear equations. It takes two arguments: a vector of equations (including named equations), and a vector of variable names to be solved:
## (%i1) a:x = 2*y
## (%o1) x = 2 y
## (%i2) b:y = x+1
## (%o2) y = x + 1
## (%i3) solve([a,b],[x,y])
## (%o3) [[x = - 2, y = - 1]]
Vectors are created using brackets:
## (%i1) v:[1,2,3]
## (%o1) [1, 2, 3]
creates a vector v of length three. Individual elements of vectors can be extracted with brackers, indexing is 1-based:
## (%i1) v:[a,b,c]
## (%o1) [a, b, c]
## (%i2) v[1]
## (%o2) a
Matrices can be created using function matrix
and wrapping individual lines in brackets:
## (%i1) matrix([1,2],[3,4])
## [ 1 2 ]
## (%o1) [ ]
## [ 3 4 ]
. is inner product. For instance:
## (%i1) u:[u1,u2]
## (%o1) [u1, u2]
## (%i2) v:[v1,v2]
## (%o2) [v1, v2]
## (%i3) u . v
## (%o3) u2 v2 + u1 v1
~ is outer product (vector product), defined in vect package:
## (%i1) load("vect")
## (%o1) /usr/share/maxima/5.43.2/share/vector/vect.mac
## (%i2) u:[u1,u2,u3]
## (%o2) [u1, u2, u3]
## (%i3) v:[v1,v2,v3]
## (%o3) [v1, v2, v3]
## (%i4) express(u ~ v)
## (%o4) [u2 v3 - u3 v2, u3 v1 - u1 v3, u1 v2 - u2 v1]
determinant
(not det
!)