# Maxima Primer

## 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 titled "Xmaxima: console". Alternately you may edit the blue portions in this buffer, and click on them, to see the result evaluated in that window 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 Website 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 modified>result</result>.

Maxima can calculate indefinite integrals.

- integrate( x/(1+x^3),x ); returns <result modified>result</result>
- as well as definite integrals within an interval, from 0 to 1, in the following example:
  integrate( 1/(1+x^2), x, 0, 1 ); returns <result modified>result</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 modified>result</result>
- limit( sin(3*x)/x, x,0); evaluates to <result modified>result</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 modified>result</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 modified>result</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 modified>result</result>
- solve(x^2-5*x+6 =0,x); produces <result modified>result</result>

##### Linear Algebra

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

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

  The matrices can then be added, for example:

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

Then the procedure can be called. Fib[8]; gives <result>21</result>

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 modified>result</result>
- ode2('diff(y,x) -y = 1, y,x) returns <result modified>result</result>
- ode2('diff(y,x,2) - y = 1, y,x) gives <result modified>result</result>

#### Defining a Function

The standard form is

- f(3) gives <result>f(3)</result>
- f(x):=x+2
- now f(3) gives <result>5</result>

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 <result>7</result>
- , then block([v3],v3) gives <result>v3</result>.

An example in a function:

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

                                              2
                                       (y + 2)  + 25

  </result> 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 <result>

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

  </result>

Using for:

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

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 <result>385</result>

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 <result modified>this output</result>