Supplement 1
Using Mathematica

Mathematica is a general system for doing mathematical computations.  It not only can do the things a traditional calculator can do, but also can do symbolic and algebraic operations.  It can also generate graphic outputs.  Even when doing numerical operations, Mathematica can give either exact results or answers to the precision desired.

I. Launching Mathematica

In the PC Lab, click the Mathematica icon in the [Applications] folder.  If you are using a computer in conference center, type
		mathematica

A notebook frontend, including a typeset palette, a menu, and a empty document (notebook) window, will pop up.  The notebook frontend looks pretty much the same even on different type of computers, such as Sun, PC, Next, Machitosh, etc.  The notebook frontend provides pull-down menu, mouse-based commands and editing, multiwindows, high-resolution graphics, ....  One can use the notebook frontend to enter commands and data, to store calculations and Mathematica output, and  to edit any information used by Mathematica.  
	When an empty Notebook window appears on the screen, one can enter input to be evaluated by the Mathematica kernel.  As soon as one starts typing,  a cell is created; this is indicated by a cell bracket along the right edge of the Notebook window.  One can move the cursor (which is a vertical black bar) around to modify the input.  When the input is completed, press [Shift]-[Enter].  The evaluation of the first input may take a while for the computer to load the kernel into the memory.
	To exit Mathematica, 
		press [Alt] key and [F4] key together on PC 
	or 	press [mod1] key and [q] key together on Sun
	or 	use the mouse to click on [File] to bring up a menu and then select [Quit].  
The [mod1] key is one of the most important keys used by Mathematica on Sun workstations.  One can find out where the [mod1] key locates by bring up the [X-environment information] in the [Help] menu.

II. Getting start

Input

Whenever you finish input to Mathematica, press [Shift]-[Enter].  This tells Mathematica to process the input, and produce a result.  A multiple line input (by using [Enter] to separate lines) is allowed.

Example:

12323 + 11231 - 123123 + 123 - 23453

Interrupting

To stop Mathematica in the middle of a calculation, 
		press [Alt]-[.] (holding [Alt] key and [.] key down at the same time) on PC
	or	press [mod1]-[.] (holding [mod1] key and [.] key down at the same time) on Sun.

Exiting

press [Alt]-[F4] (holding [Alt] key and [F4] key down at the same time) on PC
	or	press [mod1]-[q] (holding [mod1] key and [q] key down at the same time) on Sun.

Scrolling through a Mathematica session

Since Mathematica stores all inputs and outputs in a Notebook, one can scroll backwards and forwards by using the keyboard or the mouse.

Getting help

Pressing  [F1] for context sensitive help. Click [Help] to bring a help menu.

Spacing

In Mathematica input, spaces after or before comma ",",  parentheses, and brackets are usually ignored.  For example,
		Plot[Sin[x],{x,-2,2}]
is the same as
		Plot[  Sin[x],      {x     , -2,   2}]
A space between two variables CANNOT be omitted.  For example, "x y" (or with more spaces in between) means the product of x and y while "xy" stands for another variable or object.

III. Notebooks

Documents in Mathematica are called Notebooks.  One can begin a Notebook (just like a document in a word processor) by typing.  One can create a Notebook, save it to a disk, open it and edit, and print it.  It contains documents in which text, Mathematica inputs and outputs, and graphics can be joined together.  These lecture notes, for example, are Notebooks.

Creating a New Notebook

To create a new Notebook, choose [New] from the [File] menu.  To do this, move the mouse pointer to [File] on the menu bar and click.  Then move the mouse pointer to [New] and click, and a Notebook window titled "Untitled-1" will appear.  Once one starts typing, a cell will be created to hold the input.   
Note: Every time when Mathematica is load in, a new notebook called "Untitled-1" will automatically created.

Opening Notebooks

To open an existing Notebook:  choose [Open] on the [File] menu, and select the directory under which the Notebook exists, and then select the Notebook.  
	Mathematica can open a Notebook in a window labeled with the Notebook's name.  One can open any number of Notebook windows at one time, and information can be transferred from one Notebook to another by copying and pasting.  Notebooks are ASCII files, and usually have ".nb" as their file extensions.  There are several other kinds of files that can be opened as new Notebooks:
	ASCII file
 		ASCII files from any text editor (such as textedit, vi, ...) can be opened with all the text as a single cell.
 	Bitmap file
 		Graphic bitmaps saved by Paintbrush can be opened as a Notebook with a single graphic cell.

Saving Notebooks

After working on a Notebook, use the [Save] in the [File] menu to save the changes made.  If the current Notebook is newly created, i.e., still untitled, (not yet been saved), the Save dialog box will give you an option of naming the Notebook.  One can also specify the location where the Notebook should be saved by giving the disk drive and the directory.
	The [Save As] in the [File] menu saves a Notebook after asking one to give it a name, even when the Notebook already has one.  This is useful especially when one wants to keep several versions of the same Notebook.  
	The [Save As Special] in the [File] menu allows to save a Notebook in other format such as, TeX and HTML.

Note: Saving the changes before doing any computation is highly recommended

Closing Notebooks

To close the current Notebook, click the close box in the upper-left corner of the Notebook window and move the mouse pointer to [Close] and click.

Printing Notebooks

To print the current Notebook, use the [Print] in the [File] menu.  [Printing Options] can be used to specify paper dimensions and other things.
	One can also print any selected cell or contiguous group of cells instead of print the whole Notebook. To do this, first make the selection and then choose [Print Selection] in the [File] menu to print.  [Printing Options] may be used to specify page size and other things.

IV. Cells

A cell is the basic unit of organization in a Notebook.  Each cell contains one kind of information: text, input or output, or graphics.  Cells can be selected individually and moved to other part of the Notebook or another Notebook.  Cells can also be grouped together to form "sections" or "chapters".  Each cell can have its own font, face, size, and color.

Creating a New Cell

There are several ways to create a new cell.  When a new Notebook is opened, it is empty (no cell).  However, as soon as something is typed in, Mathematica creates a new cell to hold the typed input.  A cell can be created beneath any existing one by placing the cell insertion pointer at the bottom edge of the existing cell and typing.

Selecting a contiguous range of cell

Click the cell bracket to select a cell.  When a cell is selected, its bracket is highlighted.  To select a contiguous range of cells, click the beginning cell or the last cell to select it, and then drag to extend the highlight across the contiguous range of cells

Cell Options (the [Cell] menu)

In Mathematica, cells may contain input or output, explanatory text, titles, headings, or graphics.  In other words, different cells have different attributes.  
	The Mathematica frontend assigns some attributes to a cell automatically when it is created.  However, one can assign (or change) attributes by using commands in the [Cell] menu.  Choosing a command in [Cell] menu activates the attribute for the selected cells and makes a check mark next to it.  Choosing the command again deactivates the attribute and removes the check mark.

Different Forms

There are four different forms for regular cells:
	InputForm
	OutputForm
	StandardForm
	TraditionalForm
as follows:

Integrate[x^4, {x, 1, y}]

Integrate[x^4, {x, 1, y}]           4
Integrate[x , {x, 1, y}]

(∫_1^y) (x^4) \[DifferentialD]x

(∫_1^y) (x^4) \[DifferentialD]x

Forms can be converted to another one by clicking [Cell][Convert to].  To type the mathematical formula/expression in traditional form directly, one can use the typeset palette.

Cell Properties

A cell can have following properties:
		Open
		Editable
		Edit Duplicate
		Evaluatable
		Active
		Initialization
Open: indicates that the content of cell will be displayed.
Editable: indicates that a cell can be edited.
Edit Duplicate: indicates that when editing a cell, the cell duplicates itself and all changes will be made to the copy instead of the original cell.
Evaluatable: indicates that a cell contains valid Mathematica commands which can be evaluated.
Active: indicates that a cell is active and wheneve you click on this cell, certain action will be taken.
Initialization: indicates that a cell will be evaluated automatically whenever the Notebook is opened.

Groups of Cells

A sequence of contiguous cells can be grouped together.   Groups of cells are indicated by additional brackets on the right side of the Notebook window.
	To group a range of cells together: select the range of cells (they must be contiguous cells), and choose the [Group Cells] in the [Cell][Cell Grouping] menu.
	To undo the grouping, select the group and choose [Ungroup Cells] in the [Cell][Cell Grouping] menu.
	A grouped range of cells can be closed so that only the first cell in the group is visible.  To do this, select the group, and choose [Open/Close Group] in the [Cell] menu. Another way to open/close a group of cells is double click the most outside cell bracket.

Merge/Divide Cells

A sequence of contiguous cells can be merged into a single cell.  To merge a range of cells together: select the range of cells (they must be contiguous cells), and click the [Merge Cells] in the [Cell] menu.
 	To divide a single cell into two: place the cursor at the position where you want to break the cell and click [Divide Cells] in the [Cell] menu.

Key combinations

Athough mouse is convenience, key combinations can be very useful to speed up inputing formula into Mathematica.  Pay attention to the key combinations on the right-side of the menu items.

V. Doing Mathematics with Mathematica

Arithmetic Operations

x^y		power
                    -x		minus
                    x/y		divide
                    x y z		multiply
                    x*y*z		multiply
                    x+y+z		add

Precision

When trying to perform arithmetic operations on integers, one will get an exact result.

Examples:

(2^123)

(34/26)

(1/3) + (1/5)

However, one can always force Mathematica to output an approximate result (to six significant figures) by ending an input line with //N.  (Remember: N is in capital letter) 
                  expr //N       approximate numerical value of expr

Examples:

N[(1/3) + (1/5)]

N[(2^123)]

One can use the build-in function N to get a numerical result up to any degree of precision.
                  N[expr]         approximate numerical value of expr
                  N[expr, n]     numerical value of expr to n decimal digits

Examples:

N[(1/3) + (1/5)]

N[(1/3) + (1/5), 30]

N[π]

N[π, 50]

The function N[ ] or the suffix //N forces Mathematica to output a numerical result no matter what kind of operations it performs.  However, the function N[ ] can be used to specify a desirable precision, and can be used in an expression.  For example, Eigenvalues[N[m]] will return the numerical eigenvalues of the matrix m.

Complex Numbers

Mathematica can perform operations on complex numbers.  The constant I is the square root of  -1.

Examples:

(Sqrt[-4])

N[Exp[3 + π I]]

((4 + 3 I)/(2 - 5 I))

N[Sin[4 + 5 I], 20]

Basic Functions and Operations

. Arguments of functions are given in square brackets, and separated by comma.
. Names of built-in functions have their first letters capitalized.
. Multiplication can be represented by a space.
. Powers are denoted by ^.
. Numbers in scientific notation are entered, for example, as 3.4544 10^-3.

All built-in functions use their full names unless there are standard abbreviations for them.  For examples, Conjugate[z] is the complex conjugate of z, and Sin[x] is the sine function.

Here is a list of some fundamental functions and constants in Mathematica.

. functions
	Sqrt[x]			square root
	Exp[x]				exponential
	Log[x]				natural logarithm
	Log[b,x] 			logarithm of x to base b
	Sin[x], Cos[x], Tan[x]	trigonometric functions
 ArcSin[x], ArcCos[x], ArcTan[x]	inverse trigonometric functions              
	n!				n factorial 
	Abs[x]				absolute value
	Round[x]			closest integer to x
	Mod[n,m]			n modulo m (remainder on division)
	Random[]			pseudorandom number between 0 and 1
  Max[x, y, ...], Min[x, y, ...]		maximum, minimum of x, y, ...
	FactorInteger[n]		prime factors of n
	Re[z]				real part of a complex number z
	Im[z]				imaginary part of a complex number z
	Conjugate[z]			complex conjugate of z
	Arg[z]				the argument of z

. constant
	Pi		= 3.1415926.......
	E		= 2.71828.........
	Degree	= Pi/180  degree to radian conversion factor
	I		= square root of -1
	Infinity	= infinity

Example:

N[Sin[20 Degree]]

One can also type
		?command
to access the online help.

Building Up calculations

Using Results

In Mathematica, % stands for the last result, %% the last but one result; and so on.  In addition, %n stands for the result on the output line Out[n].

Examples:

Sin[2.234]

4 %

Cos[3.13]

% + I %%

%%%% + I %%

Defining Variables

It is often convenient to give names to intermediate results.  As in standard mathematics or in other programming languages, this can be done by introducing named variables.

Examples:

x = 4

(x^3)

Lists of objects

Mathematica arranges its data in the form of lists.  A list treats several objects (like several numbers, or functions) as a single entity.  A list like {2, 3, 4, 1} is a collection of four objects (numbers).  When an operation is performed on it, it is treated as a single entity.

Examples:

v = {6, 3, 5}

v + 2

(v^2)

Here are some common operations on lists.
	Range[n]		create the list {1, 2, 3, ..., n}
	Range[n,m]		create the list{n, n+1, n+2, ... ,m}
	Range[n,m,d]		create the list {n, n+d, ..., m}
Note: If n or m is not an integer, it will be rounded to the nearest smaller integer.
	{a,b,c,d,e}		create the list {a,b,c,d,e}

If v is a list,

list[[i]]			the i-th element of list
	list[[{i,j,...}]]		the sublist consisting of i-th, j-th, ... elements of list
	list[[i]]=value		assign value to the i-th element of list
	list[[i,j,...]]		an element of a nested list

Examples:

t = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

t[[1]]

t[[1, 2]]

t[[1, 2]] = 10

t

t[[1]] = 10

t

When accessing a nonexisting element of the list t, Mathematica gives an error message.

Example:

t[[1, 2]]

Mathematica Packages

Mathematica has a large number of built-in functions.  Yet, they cannot cover all possible application areas.  Mathematica comes with a variety of "packages" for specific applications.  A Mathematica package is a standard text file, and can be read in by using the command <<.

Example:

<< Graphics`PlotField`

PlotVectorField[{x, y}, {x, -4, 4}, {y, -3, 3}];

The two packages we need most often are Graphics`PlotField` and Calculus`LaplaceTransform`

VII. Formulae and Mathematical Operations

Representing Formulae

Functions in Mathematica can be used in a symbolic way.

Examples:

(Sqrt[8]) + (Sqrt[12])

((((Sqrt[x + y])))^6)

Substitution of Variables

x=value				define a value for x as value
       x=.				remove any definition for x
       expr /. x->value			replace x by value in the expression expr
   expr /. {x->xval, y->yval}		perform the replacements
Variables in a formula can be substituted by any (symbolic or numerical) value.

Examples:

1+x^2 /. x->4

y=3+x^2

y /. x->1+a

x

From the last four lines, it can be seen that the substitution has no effect on the value of x; in other words, the substitution is restricted in the evaluation of the expression.

Algebra

Algebraic expressions can usually be written in many different ways.  Mathematica provides a variety of functions for converting expressions from one form to another.

Expand[expr] 
		multiply out products and powers, but leave denominators in factored form
	ExpandAll[expr]     
		apply Expand everywhere
	Factor[expr]
		reduce to a product of factors
	FactorTerms[expr]
		pull out common factors from each term
	Together[expr]
		put all terms together over a common denominator
	Apart[expr]
		separate into terms with simple denominators
	Cancel[expr]
		cancel common factors between numerators and denominators
	Collect[expr,x]
		group together terms involving the same powers of x
	Simplify[expr]
		give the simplest form of expr found
	Coefficient[expr,form]
		the coefficient of form in expr
	Exponent[expr,form]
		the maximum power of form in expr
	Numerator[expr]
		the numerator of expr
	Denominator[expr] 
		the denominator of expr

Examples:

e=(x-1)^2 (2+x)/((1+x)(2-x)^2)

Expand[e]

ExpandAll[e]

Together[%]

Apart[%]

Factor[%]

Simplify[e]

e=Expand[(3+2x+y)^3]

Collect[e,x]

Example:

Expand[Sin[x]Cos[3x],x,Trig->True]

To suppress the output for a long expression,
 	command;     
		execute command, but do not print the result
  	expr // Short
  		show expr in a one-line outline form
  	Short[expr,n]
		show expr in n-line outline form
	Length[expr]
		show the total number of terms in expr

Examples:

Expand[(2+3x+29y+31z)^10];

Expand[(2+3x+29y+31z)^10] // Short

Calculus

Symbolical Computations

Each of the following operations gives an exact result unless it involves decimals or is forced to output a numerical value by //N or N[ ] .

D[f,x]
		the partial derivative of f with respect to x
	D[f, x1, x2, ...]
		the multiple partial derivative of f with respect to x1, x2, ...
	D[f, {x, n}]
		the n-th derivative of f with respect to x
	Dt[f]
		the total differential df
	Dt[f,x]
		the total derivative of f with respect to x
	Integrate[f, x]
		the indefinite integral of f with respect to x
	Integrate[f, {x, xmin, xmax}]  
		the definite integral of f with respect to x from xmin to xmax
	Integrate[f, {x, xmin, xmax}, {y, ymin, ymax}]
		the definite integral of f 
	Sum[f, {i, imin, imax}] 
		the summation of f with i run from imin to imax
	Sum[f, {i, imin, imax, di}]
		the summation of f with i increasing in steps di
	Product[f, {i, imin, imax}]
		the product of f with i run from imin to imax
	Limit[f, x -> x0]
		the limit of f as x goes to x0
	Sum[f, {i, imin, imax}, {j, jmin, jmax}]
		the summation of f
	Series[f, {x, x0, n}]
		a power series expansion of f at the point x = x0  to order (x - x0 )^n
	Normal[series]
		truncate a power series to an ordinary expression

Examples:

f=Expand[(x+y)^3]

D[f,x]

Dt[f]

Dt[f,t]

Integrate[f,x]

Integrate[f,{x,0,3},{y,0,x}]

Sum[x^i y^j,{i,0,3},{j,0,i}]

Sum[1/i^3,{i,1,Infinity}]

N[%]

Product[x^i/i, {i,1,10}]

Series[Exp[-a t](1 + Sin[2 t]),{t,0,4}]

Series[f[t]^3,{t,0,3}]

Normal[%]

Sin[x]/x /. x->0

Limit[Sin[x]/x,x->0]

Numerical Computations

A list of functions for numerical computations are given below:
	NIntegrate[f, {x, xmin, xmax}]
		the numerical definite integral of f on the inteval (xmin, xmax)
	NIntegrate[f, {x, xmin, xmax}, {y, ymin, ymax}]
		the numerical definite integral of f
	NSum[f, {i, imin, Infinity}]
		the summation of f 
	NSum[f, {i, imin, Infinity, di}]
 		the summation of f with i increasing in steps di
	NSum[f, {i, imin, imax}, {j, jmin, jmax}]
		the summation of f
	NProduct[f, {i, imin, Infinity}]
		the product of f

Remark:  The combination of N[ ] and Integrate[ ] can be used to get a numerical value of a definite integral, but this is different from the function NIntegrate[].  The former integrates the integrand analytically and then evaluate its numerical result while the later integrates the integrand numerically right away.  Similarly, N[Sum[ ]] is different from NSum[ ], and N[Product[ ]] different from NProduct[ ].

Remove[x, y]

Equation Solving

Symbolic/Exact

To test whether the left-hand side of an equation is equal to its right-hand side, use
	lhs == rhs

There are several functions in Mathematica which can be used to solve an equation or a set of equations symbolically.
	Solve[lhs==rhs, x]
		solve an equation lhs == rhs for x
 	Solve[{lhs1==rhs1, lhs2==rhs2, ...}, {x1, x2, ...}]
		solve equations {lhs1= rhs1, lhs2= rhs2, ...} for {x1, x2, ...}

Examples:

Solve[x^2+3x == 4, x]

Solve[{2x+y==1, x+2y==3}, {x,y}]

To solve a differential equation, we use the function DSolve:
	DSolve[eqns, y[x], x]
 		solve a differential equation for y[x], taking x as the independent variable
	DSolve[eqns,{y1[x],y2[x],...},x]
 		solve the system of differential equations for y1[x], y2[x], ...

Examples:

DSolve[y'[x]==a y[x],y[x],x]

y[x]+y'[x]+y[0]/.%

DSolve[y'[x]==a y[x],y,x]

y[x]+y'[x]+y[0]/.%

DSolve[{x'[t]==y[t],y'[t]==a x[t]},{x[t],y[t]},t]

DSolve[{x''[t]+4 ==0,x[0]==x[1]},x[t],t]

Numerical Equation Solving, Optimization and Differential Equation Solving

NSolve[lhs == rhs, x]
		solve a polynomial equation numerically
	NSolve[{lhs1 == rhs1, lhs2 == rhs2, ...}, {x, y, ... }]
		solve a system of polynomial equations numerically
	FindRoot[lhs == rhs, {x, x0}]
		search for a numerical solution for the equation, starting with x=x0
	FindRoot[{lhs1 == rhs1, lhs2 == rhs2, ...}, {x, x0}, {y, y0}, ... ]
		search for a numerical solution for the system of equations, starting with x=x0, y=y0, ...
	FindMinimum[f, {x, x0}]
		search for a local minimum of f, starting with x=x0
	FindMinimum[f, {x, x0}, {y, y0}, ...]
		search for a local minimum of f, starting with x=x0,  y=y0, ...
	NDSolve[eqns, y, {x, xmin, xmax}]
 		solve a differential equations numerically for y, with the independent variable x ranging from xmin to xmax
	NDSolve[eqns, {y1, y2, ...}, {x, xmin, xmax}]
		solve a system of differential equations numerically for {y1, y2, ...}

The two of the main differences between NSolve and FindRoot are 
	1. NSolve can only handle polynomial/rational equations while FindRoot can handle any type of nonlinear equation;
	2. however, FindRoot can only find one solution no matter how many solutions the equation has, while NSolve can find "all" solutions.

Examples:

NSolve[x^5==1.5 x^3+1,x]

NSolve[{x^5==1.5 y x^3+1+y^3,y^4+y^2 x==1},{x,y}]

FindRoot[Cos[x]==x,{x,0.4}]

FindRoot[{Cos[x]==y x, y^2 == Sin[x^2]},{x,0.4},{y,0.1}]

FindMinimum[x Sin[x],{x,2Pi}]

FindMinimum[x^2 y^4-x-y^2+2,{x,2},{y,1}]

NDSolve[{y'[x]==y[x]x,y[0]==1},y,{x,0,2}]

Plot[Evaluate[y[x] /. %],{x,0,2}]