uDevil's Maxima Examples

Maxima is an open-source computer algebra system. You can download the program at http://maxima.sourceforge.net.

Below are a number of examples of Maxima commands. Commands may be executed by typing them at the Maxima prompt and pressing Shift+Enter.

Factor a polynomial:

Solve a system of linear equations:
eq1: x+y+z=0; eq2: 2*x+3*y+z=2; eq3: 3*x+7*y+2*z=4;

Use the quadratic formula:
a: 2; b: 3; c: -4; solve(a*x^2+b*x+c,x);
float(%); /*display the last result as a floating point number */

After entering the first several commands above, your wxMaxima screen will look something like the image below:

Solve a system of nonlinear equations:
load("mnewton"); /* Must load this package before using the mnewton function */

Maxima uses radians for angle measure, so define a macro to convert
degrees to radians and use it to calculate the value of a trig function:
deg(x)::= x*%pi/180;

Use the above macro in defining a system of nonlinear equations then solve the system.

Partial fraction expansion:

Indefinite integral of a polynomial in x wrt x:

Definite integral from 0 to 1:

Differentiate a function of x wrt x:

limit(sin(x)/x,x,inf); /* limit of sin(x)/x as x goes to + infinity */ /* Note: if we wanted minus infinity, we'd use minf. */
/* limit as x->0 */ limit(cos(x)/x,x,inf);

Solve a linear differential equation w/ initial conditions:
Note: desolve will also solve systems of linear differential equations.

a:1; b:2; c:1; /* define constant values */
eq1: a*'diff(f(x),x,2)+b*'diff(f(x),x,1)+c=0; /* Equation to solve */
atvalue('diff(f(x),x),x=0,1.0); /* define initial conditions */

Matrix operations:
N: matrix([1,0],[0,2]); /* Define a matrix, N */
M: matrix([2,3],[3,4]); /* Define a another matrix, M */
L: M.N; /* Assign to L the matrix product of M and N*/
eigenvalues(L); /* eigenvalues of L */
eivenvectors(L); /* eigenvectors of L */
invert(M); /* inverse of matrix M */
A: M*N; /* Assign to A the element by element product of M and N */
B: M-N; /* Assign to B the element by element difference of M and N */
C: M+N; /* Assign to C the element by element sum of M and N */
determinant(C); /* Calculate the determinant of C */

Plot a function, set x and y ranges, and set grid:
plot2d(sin(x)/x,[x,-20,20],[y,-.5,1.5],[gnuplot_preamble,"set grid"]);

Back to my home page...