Using Mathematica for UNIX
Starting in batch mode
The following is the method to run Mathematica as a batch job:
math -batchinput -batchoutputm < infile > outfile
( Here please note < , > )
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
- Arguments to functions are given in square brackets.
- The first letter of build in functions are upper case
- Multiplication can also be represented by spaces.
- Powers are denoted by ^.
- Complex numbers
x + Iy => The complex number (x+iy)
Re[z], Im[z], Conjugate[z], Abs[z], Arg[z]
- Using previous results
% => The last generated results
%% => Next to last
%n => The result of the n-th line
- Manipulating Variables
x = value, x = y = value,
x = . or Clear[x]
x y means xy
x^2y means (x^2)y not x^(2y)
- 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
DerivativesD[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]
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)
Array, IdentityMatrix, DiagonalMatrix, PartDimensions, 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.
Axes, AxesLabel, AxesOrigin, DefaultFont, DisplayFunction
Frame, FrameLabel, FrameTicks, GridLines, PlotLabel
PlotRange, Ticks, DisplayFunction(options that cannot be used with 'show') PlotStyle,
PlotPoints, MaxBend, PlotDivision, CompiledThe 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}]
Axes, AxesLabel, Boxed, ColorFunction, DefaultFont
DisplayFunction, FaceGrids, HiddenSurface, Lighting
Mesh, PlotRange, Shading, ViewPoint
Default View point = {1.3, -2.4, 2}
- The following functions are awailable for ploting of lists.
- Mathematica also has the ability to do parametric plots. More information on parametric plots can be found on page 169.
- There is a command show available in mathematica that can be used to redraw plots, and to change the options after the initial plot.
- 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.
ListPlot, ListPlot3D, ListContourPlot, ListDensityPlot
NOTE:
<< 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
Mathematica External interface
- Dump creates a huge binary file, therefore one may run out of quota, when trying to run Dump command
- For more information on generation of c,fortqran code, Tex input or spicing files please refer to page 182 through page 186 of Mathematica book.
<< name: Reads in a plaintext file.
expr >> name: Outputs 'expr' to a file as plaintext.
expr >>> name: DAappend 'expr' to file.
!!name: Display content of plain text file.
Save: Save[" name", f,g,...] save definition for variableDump: In systems such as unix, one has the ability to save the
complete state of mathematica.
Dump[" namefile"]
math -x < filename> to start from dump file.
NOTE:
Last updated:
February 04, 2011