University of Southern California

ITS Information Technology Services

Using Mathematica for UNIX

Documentation and Help

There is a man page available for Mathematica. To read the manual page type:

`man math`

Mathematica does not provide help within the math command. There is a command called mathbook which will allow you to access a Mathematica reference of available functions.

Inside Mathematica you can use the following three methods to get information on functions.

` ?function Gives a brief description of the function`
`function Gives a extended description of the function`
`?Ab* Shows all functions starting with "Ab"`
`?* Shows all functions`

Helpful Hints when using Mathematica

1. Arguments to functions are given in square brackets.
2. The first letter of build in functions are upper case
3. Multiplication can also be represented by spaces.
4. Powers are denoted by ^.
5. Complex numbers
``` x + Iy => The complex number (x+iy) Re[z], Im[z], Conjugate[z], Abs[z], Arg[z] ```
6. Using previous results
``` % => The last generated results %% => Next to last %n => The result of the n-th line ```
7. Manipulating Variables
``` x = value, x = y = value, x = . or Clear[x] x y means xy x^2y means (x^2)y not x^(2y) ```
8. List:
When you collect together a bunch of entries and treat them as a single entry, then it's named as a list.
``` Ex: ln[1] := {3, 5, 1} Accessing or Manipulating a single elemnet Part[list,i], or list[[i]] ```

Algebraic Equations

Mathematica has the ability to handle both numeric and symbolic calculations. This allows users to enter algebraic formulas. This has the added advantage of being able to enter the values as they are read, and be able to evaluate results for different values.

Replacing variables with values

``` EX: Replacing 'x' exp /. x -> value Several replacements exp /. { x -> xval, y -> yval } ```

Some important functions to manipulate equations

```Expand, Factor, Simplify, ExpandAll Together, Apart, Cancel, Collect Expand[exp, Trig -> True] Factor[exp, Trig -> True] ComplexExpand, PowerExpand ```

More Important Functions

Derivatives
`D[f,x], D[f,x1,x2,...], D[f, {x,n}], Dt[f], Dt[f,x]`

Intergration
`Intergrat[f,x], Intergrate[f, {x, xmin, xmax}],`

Intergrate
`[f, {x, xmin, xmax}, {y, ymin, ymax}]`

Sums & Products
```Sum[exp, {i, imin, imax}], Sum[ exp, {i, imin, imax}, {j, jmin, jmax}] Product[exp, {i, imin, imax}]```

Solving Equations
`Solve[lhs == rhs, x]`

Creating functions

Just as mathematica has built-in fuctions, users can also create their own functions.
``` Ex: f[x_] := exp (Defines the function f) You can use "?f" to show the definition of f, & Clear[f] clears the definition of f. Look at the following example of transformation rules for functions. Ex: 1+ f[x] + f[y] ```
The three transformation rules shown below transforms the expression differently.
```x -> value f[x] -> exp (or value) f[t_] -> exp ```

Vectors and Matrices

Lists and lists of lists are used in mathematica to represent vectors and matrixes.

```{a, b, c} => vector(a, b, c) {{a,b,c}, {c,d,e}} => matrix(a b c) (c d e) ```
Useful functions
`Array, IdentityMatrix, DiagonalMatrix, Part`
Dimensions, MatrixForm,
Inverse, MatrixPower, Det, Transpose
EigenValue, EigenVector

Graphics

Unlike some other programs, Mathematica allows it's users to plot actual algebraic functions. One can do 2-d and 3-d plots with a cutomized view port. Also, users have the freedom to change the settings in graphs to customize them accordingly.

Ploting functions (2-D)
```Plot[f, {x, xmin, xmax}] Plot[f1,f2,...., {x, xmin, xmax}]```
More examples can be found on page 136.

In general mathematica selects the suitable `options` for the graph, but if one wants, the option command is there to change the choices.
Important options
```Axes, AxesLabel, AxesOrigin, DefaultFont, DisplayFunction Frame, FrameLabel, FrameTicks, GridLines, PlotLabel``` PlotRange, Ticks, DisplayFunction
`(options that cannot be used with 'show') PlotStyle,` PlotPoints, MaxBend, PlotDivision, Compiled
Ploting functions (3-D)

The command for 3-D plots is Plot3D. After a plot, the command `show` can be used for redrawing and changing options.

`Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}]`

Important Options
```Axes, AxesLabel, Boxed, ColorFunction, DefaultFont DisplayFunction, FaceGrids, HiddenSurface, Lighting Mesh, PlotRange, Shading, ViewPoint Default View point = {1.3, -2.4, 2} ```
Ploting lists of Data

The following functions are awailable for ploting of lists.

`ListPlot, ListPlot3D, ListContourPlot, ListDensityPlot`
NOTE:
1. Mathematica also has the ability to do parametric plots. More information on parametric plots can be found on page 169.
2. There is a command show available in mathematica that can be used to redraw plots, and to change the options after the initial plot.
3. There are a lot more different plotting functions available with mathematica, such as animation plots. If these functions are not loaded at startup one may need to explicitly load them before calling a function.

4. ``` << Graphics'Graphics' load a package with additional graphics function LogPlot, LogLogPlot, LogListPlot, LogLogListPlot PolarPlot, ErrorListPlot, TestListPlot, BarChart, PieChart, PlotvectorField, SphericalPlot3D << Graphics'Animation' load animation package ```