Maxima cheat sheet

Operators

Most Maxima operators are intuitive but I'm keeping a list of ambiguous ones.

In most cases:
- Scalars: use '*' and '^'
- Matrices and vectors: use '.' and '^^'
- Floats: use '.' to represent decimals (e.g. '3.14' and not '3,14')

Operator Designation Example
* - Scalar multiplication

- Component wise matrix/vector multiplication
% b*a*b
\( a \ b^2 \)

% [a, b, c]*2
\([2a,2b,2c]\)

% matrix([2,2],[3,3]) * 2
\(\begin{pmatrix}4 & 4\\ 6 & 6\end{pmatrix} \)

% matrix([2,2],[3,3]) * matrix([2,2],[3,3])
\(\begin{pmatrix}4 & 4\\9 & 9\end{pmatrix}\)
  - Non commutative scalar multiplication

- Matrix (vector) multiplication
(recommended: surround with spaces)

- Decimal point for floats
% b . a . b
\(b\mathit{ . }a\mathit{ . }b\) /* can't factor to \(b^2\) */

% [a,b,c].[a,b,c]
\(c^2+b^2+a^2\)

% matrix([2,2],[3,3]) . matrix([2,2],[3,3])
\(\begin{pmatrix}10 & 10\\15 & 15\end{pmatrix}\)

% 2.1 + 2
\( 4.1 \) /* Float value: "four point one" */
** or ^ - Scalar exponentiation

- Component-wise matrix/vector exponentiation
% a^2
\(a^2\)

% [a,b,c]^3
\([a^3,b^3,c^3]\)

% matrix([2,2], [3,3])^2
\(\begin{pmatrix}4 & 4\\9 & 9\end{pmatrix}\)
^^ - Non commutative scalar exponentiation

- Matrix/vector exponentiation
(i.e. chaining multiplications)
% (a*b)^^2
\((a.b)^2\) /* Prevents expansion to \( a^2.b^2 \) */

% [a,b,c]^^2
\( \Big( c^2+b^2+a^2 \Big) \)

% matrix([2,2], [3,3])^^2
\(\begin{pmatrix}10 & 10\\15 & 15\end{pmatrix}\)

Assignment, equality etc.

Operator Designation Example
: - Assign value, expressions etc to a variable % x: 2
\( 2 \)

% vec: [a, b, c]
\( [a, b, c] \)

% mat : matrix([2,2],[3,3])
\(\begin{pmatrix}2 & 2\\ 3 & 3\end{pmatrix} \)

% myExpr : x*y + c
\( x.y + c \)
:= - defines a function % f(x) := 2*x + 3
\(\operatorname{f}(x)\operatorname{:=}2 x+3\)

% f(5)
\(13 \)
= Equation operator
- Defines (unevaluated) equations

Can be evaluated as:
- Equation
- Substitution expression
- Boolean comparison
% eq1: x + 3 = 0
\( x + 3 = 0\) /* not evaluated */

% solve(eq1, x)
\(\left[ x=-3\right] \) /* solved in 'x' */

% subst(x=-3, x*x);
\( 9 \) /* substitutes x */

% subst(solve(eq1, x), x*x);
\( 9 \) /* Need to solve equation first */

% is( 2+2 = 4)
true /* is(expr) to evaluate and compare */

Vector

A vector is a list of number, index start from 1 (just like in mathematics) and not 0 (like in programming)

% vec: [i,j,j,f];

\( [i,j,k,f] \)

% vec[2];

\(j\)

Dot product:

% [a,b,c].[a,b,c];

\(c^2+b^2+a^2\)

Cross product: '~'

% load(vect); /* needed for '~' and 'express()' */
% express([x1,y1,z1]~[x2,y2,z2]); /*express() is needed to force the expansion*/

\([y1 \ z2 \ - \ y2 \ z1, \quad x2 \ z1 \ - \ x1 \ z2, \quad x1 \ y2 \ - \ x2 \ y1]\)

I recommend to define the cross product as:

%cross(a,b) := express(a~b);

Matrix

Matrix' indices start from 1 (just like in mathematics) and not 0 (like in programming)

% mat : matrix([2,2], [3,3]);

\( \begin{pmatrix} 2 & 2\\ 3 & 3 \end{pmatrix} \)


% mat[1,1];

\(2\)


% mat[1];

\(\left[ 2\operatorname{,}2\right] \)

Substitution

Substitutes x:

% subst(x=-3, x*x);
% subst(-3, x, x*x); /* equivalent to the above */
\(9\)

Serial substitution:

% subst([x=3, y=-1, x=x+1], x^2-x+y);
/* substitute x -> 3^2 - 3 + y = 6 + y
   then y -> 6 - 1 = 5
   x=x+1 -> ignored since x was already substituted  */
\(5\)

Parallel substitution:

% psubst ([a^2=b, b=a  ], sin(a^2) + sin(b));
% psubst ([b=a  , a^2=b], sin(a^2) + sin(b)); /* order doesn't matter, most of the time...*/
% subst  ([b=a  , a^2=b], sin(a^2) + sin(b)); /* happens to be equivalent to the above */
\( \sin(b) + \sin(a) \)
As opposed to serial substitution:
% subst ([a^2=b, b=a], sin(a^2) + sin(b)); /* order always matters */
/* substitute a^2 -> sin(b) + sin(b) = 2 sin(b)
   substitute b -> 2 sin(a) */
\( 2 \ \sin(a) \)

Parallel substitution corner case:

% psubst( [x=x+1, x=3 ], x^2-x+y);  
/* In parallel it is ambiguous wether x=x+1 or x=3 should be applied, rightmost is chosen */
\( y+(x+1)^2-x-1 \)
% psubst( [x=3, x=x+1], x^2-x+y); 
\( y+6 \)

Substitute from left to right using 'ev(main_expr, e1,e2,e3)' or 'main_expr, e1,e2,e3':

% ev(x^2-x+y, x=3, y=-1, x=x+1);
%    x^2-x+y, x=3, y=-1, x=x+1; /* equivalent to ev() */
/* substitute, x then y, x=x+1 is ignored since rightmost x was already substituted */
/* warning this is equivalent to parallel substitution psubst() and not subst() */
\(5\)

Chaining

Evaluate expressions in a single line from left to right (serial evaluation)
( 1st_expr , 2nd_expr, 3nd_expr, ... )

% (x:3, x: x+1, x: x^2,  x+1); /* serial evaluation */
\(17\)
Works on the global context, i.e. assignment persists outside:
x;
\(16\)

Warning: parenthesis matter.
( . , . , )       . , . ,




Evaluate expressions in *parallel*, assignment is kept local inside 'ev()' (does not change global context)
ev(   . , . , ) or    . , . ,

Chain functions:

% ratsim(factor(expr))
/* Equivalent: */
% expr, ratsimp, factor

Misc

Todo: ev(%, nouns)

partial function application:

% diff_x(f) := diff(f, x);

Display 'alpha' 'phi' etc. as greek symbols:
(In wxMaxima)
EditConfigureWorksheet → 🗹 "change names of greek letters to greek letters"

% diff( alpha(phi(x)), x);
\( \frac{d}{d x} \alpha\left( \phi(x)\right) \) /*displays as greek symbols*/

Derivatives / Differentiation

diff( function expression, var [, degree] [, var, degree ...] )

% diff( x^2, x); /*first derivative according to x*/
\(2x\)

% diff( x^7 * y^8, x, 2, y, 2); /*1st: diff y two times, 2nd: diff x two times*/
\(2352 {{x}^{5}} {{y}^{6}}\)

Common mistake:

% f(x) := x^7 * y^8;
% diff( f, x, 2, y, 2) /* f interpreted as constant */;
\(0\)

% diff( f(x), x, 2, y, 2); /* differentiate according to 'x' */
\(2352 {{x}^{5}} {{y}^{6}}\)

Chain rule:

Use 'pdiff' package:

% diff( f(g(x)), x);
\(\frac{d}{d x} \operatorname{f}\left( \operatorname{g}(x)\right) \)

% load("pdiff")
% diff( f(g(x)), x); /*now can develop chain rule, and uses indices to designate derivatives*/  
\( {g_1}(x) {f_1}\left( \operatorname{g}(x)\right) \)

trick to avoid parenthesis when applying diff() in cascade:

% diff(diff( sin(x), x), x)

By default diff is not and 'evfun' and you can't use ev(). so:

% diff_x(f) := diff(f, x);
% declare(diff_x, evfun);

Now we can do:

% aFun(x), diff_x, diff_x;
\( \frac{{{d}^{2}}}{d {{x}^{2}}} \operatorname{aFun}(x) \)

Material

- Official doc in one page
- Cheat sheet
- More tips
- wxMaxima Self-Guided Tutorials (good section on vector operations (grad, curl etc.)
- More doc with other tricks

No comments

(optional field, I won't disclose or spam but it's necessary to notify you if I respond to your comment)
All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Anti-spam question: