Some Basic Mathematica

Applications of =

b = a + x

Further appearances of b are replaced by a + x.
x == 2y +3

Here an equation is defined for later solution.
eqn1 = x == 2y+3

Whenever "eqn1" is used in a future Mathematica expression, it represents the equation "x == 2y+3".
f[x_] := x**2

Defines a function f(x)=x2. The Underbar is important. In a later line try typing "f[y^2]" and observe the results.


expr /. x -> y

Replace all occurances of x with y in expression expr. For the above definition of "eqn1" try typing the line "eqn2 = eqn2 /. y->z".

File i/o

<< filename

Causes Mathematica to read and process commands in file "filename". If you enter a simple file name with no subdirectory information, Mathematica will look in your home directory for the file. See mathin for an example of one such input file. It is plain text that can be edited with "vi" or your favorite text editor.
x >> filename

Output the definition of x to file "filename".
x >>> filename

Append the definition of x to filename.

Save specified quantities in file "filename"

Save all your input lines

Save all your output lines

Result References

Include any of the following as part of an input expression to perform further operations on a previous result.


Use the last result generated. For example "Factor[%]" would factor the algebraic expression printed as a result of your previous command.


The one before that. For example typing "y1=%%", would place the results of your command before the last one into variable y1. Any use of "y1" in future input expressions will be replaced by those results.


If you need results from even older input lines use this. This picks up the contents of the line labeled Out[n].


Mathmatica often lets you replace individual arguments in functions with lists of arguments in the form "{a,b,c,d}" and produces a result in the form of a list of answers. This is its version of using arrays in Fortran or C.

Some Useful Functions

All internal Mathematica functions (and constants) start with un Upper case letter. It's a good idea to start your own variables and functions with a lower case letter to avoid potential conflicts.


Quit Mathematica

Partial derivative of f with respect to x. To get the nth derivative use "D[f,{x,n}]". For example try "D[x Cos[x],{x,2}]

Integrate f with respect to x. Use "Integrate[f,{x,a,b}] to do a definite integral from x=a to x=b. For example try "Integrate[x Sin[x], {x,0,Pi}]"

Solve the set of equations with respect to the listed variables.

Multiply out and take all powers in the expression "expr"


Factor the expression "expr"

Find a form of "expr" with the smallest number of terms (often but not always a factorization)

Gather all terms in the expression "expr" over a common denominator

Separate into terms with simple denominators

Cancel common factors in numerators and denominators

Group expr together by powers of x
Subscripted[f[x1,x2, ...],n]

The first n arguments of f are treated as subscripts.

Arguments i to j are subscripts k to l are superscripts.