# Maxima Primer

Maxima is a computer program for doing mathematics calculations, symbolic manipulations, numerical computations and graphics. Procedures can be programmed and then run by Maxima to do complex tasks. Much of the syntax for other languages such as Maple was copied from Maxima.

## Project and documentation links

The Help menu in Xmaxima gives you access to the following documents:

- Maxima reference manual
- Xmaxima reference manual
- Maxima home page, http://maxima.sourceforge.net
- Maxima project page, http://sourceforge.net/projects/maxima

## Getting started

To do basic operations, a line is typed, followed by a semicolon, and then entered. This can be done in the window above. Alternately you may edit the blue portions in this buffer, and click on them, to see the result evaluated above and/or inserted in this window, depending on what was specified in the html source for this file. For example clicking below

- integrate(1/(1+x^3),x)

You may double click the above formula, and the integral will be substituted into the Maxima evaluation in the other window. There are examples which you may also look at 3d plotting If you wish to have your plots appear in a separate window, go to the preferences button under file, and select separate. You may also go to the netmath page to see some more capabilities.

Here are some examples from basic calculus. To have Maxima evaluate the derivative of the function below, click on this line.

- diff(cos(x),x); returns result.

Maxima can calculate indefinite integrals.

- integrate( x/(1+x^3),x ); returns result
- ...and definite integrals with respect to x from 0 to 1.
  integrate( 1/(1+x^2), x, 0, 1 ); returns result
- plot2d(sin(x),[x,0,2*%pi])
- plot3d(x^2-y^2,[x,-2,2],[y,-2,2],[grid,12,12])

- Also, limits can be evaluated as x goes to infinity:
  limit( (2*x+1)/(3*x+2), x,inf ); produces result
- limit( sin(3*x)/x, x,0); evaluates to result

Maxima can perform calculations to arbitrary precision. The following example computes Pi to one hundred decimal places.

- block([fpprec:100],bfloat(%pi)) yields result if we took sin of this we would get 0 to to within 100 decimal places..
- block([fpprec:100],sin(bfloat(%pi))) gives result

  Maxima can solve equations. Click this line to solve the system.

- solve([x+y+z=5,3*x-5*y=10,y+2*z=3],[x,y,z]); returns result
- solve(x^2-5*x+6 =0,x); produces result

##### Linear Algebra

For example, matrices can be entered and manipulated. Click these two lines.

- A:matrix([1,2],[3,4]); gives result
- B:matrix([1,1],[1,1]); gives result

  The matrices can then be added, for example:

- A + B ; returns the sum result ...and multiplied.
- A . B ; gives the productresult
- A^^-1 evaluates to the inverse: result
- determinant(matrix([a,b],[c,d])) gives result
- Fib[0] : 0; Fib[1] : 1; Fib[n] := Fib[n-1] + Fib[n-2];

Then the procedure can be called. Fib[8]; gives 21

Maxima can solve ordinary differential equations analytically and numerically. Click the following line for an example of an analytic solution.

- ode2('diff(y,x)+3*x*y = sin(x)/x, y,x) returns result
- ode2('diff(y,x) -y = 1, y,x) returns result
- ode2('diff(y,x,2) - y = 1, y,x) gives result

#### Defining a Function

The standard form is

- f(3) gives f(3)
- f(x):=x+2
- now f(3) gives 5

Local variables:

The block construct lets us introduce local variables, and also lets us have a sequence of statements:

    block([v1:val1,v2:val2,v3,v4:val4],stmt1,stmt2,... stmtn)

the value is the value of the last statement. During the execution the variables v1,v2,... will have the values indicated. If no value is given for v3 then it will just evaluate to itself:

Thus if we set v3 globally to be 7,

- v3:7 produces 7
- , then block([v3],v3) gives v3.

An example in a function:

- g(x):=block([u:x+3,w], u:u^2, w:(y+2)^2, u+w);
- g(2) yields

                                              2
                                       (y + 2)  + 25

  Using if:
- h(x):=block([u:x+3,w], u:u^2, if (u<3) then w:(y+2)^2 else w:(y+2)^2+1, u+w);
- [h(3),h(2)] gives

                                      2              2
                              [(y + 2)  + 37, (y + 2)  + 26]

Using for:

- block([w:0], for i:1 thru 10 do (w:w+i^2)) gives done

a for loop always returns 'done as its value. To get the value you want add the w.

- block([w:0], for i:1 thru 10 do (w:w+i^2),w) gives 385

The function describe(s) returns documentation on all functions whose names include the string s. For example, if the string is "log",
describe("log");all prints this output