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:
factor(x^2+7*x+6);

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;
solve([eq1,eq2,eq3],[x,y,z]);

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 */
mnewton([y*(60*cos(x)-24)-17,y*(60*sin(x)-20)-5],[x,y],[.16,.5]);

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;
cos(deg(45));

Use the above macro in defining a system of nonlinear equations then solve the system.
mnewton([y*(60*cos(deg(x))-24)-17,y*(60*sin(deg(x))-20)-5],[x,y],[.16,.5]);

Partial fraction expansion:
partfrac((x+3)/(x^2*(2*x+1)),x);

Indefinite integral of a polynomial in x wrt x:
integrate(3*x^2+x+1,x);

Definite integral from 0 to 1:
integrate(3*x^2+x+1,x,0,1);

Differentiate a function of x wrt x:
diff(log(x^2+1),x);

Limits:
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(sin(x)/x,x,0);
/* limit as x->0 */ limit(cos(x)/x,x,inf);
limit(cos(x)/x,x,0);

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 */
atvalue('diff(f(x),x,2),x=0,-9.8);
desolve(eq1,f(x));

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...