Mathematica Lab 1, MA21a, 2000, Text only version
------------------------------------------------------------------------

*************************
*  RUNNING MATHEMATICA: *
*************************
In a UNIX terminal (i.e. at floor 1 in Science Center), type

math

at the prompt. You are then given a cursor which enumerates the 
tasks: i.e.  

"In[1]:="

To quit Mathematica, type 

Quit; 

When you start mathematica with "mathematica", you will be given 
a notebook interface. On a PC or Mac, you start the notebook as
any other application. 

********************************
*  EVALUATION OF EXPRESSIONS:  *
********************************

If you type or paste an expression into Mathematica, you evaluate 
it with <return>. In a Mathematica notebook, you have to type 
<shift><return>, while the cursor is in the cell you want to 
evaluate. 

*********************
*  BASIC OPERATORS  *
*********************

To see how Mathematica evaluates basic operations like
addition, multiplication or exponentiation, try to evaluate
the following expressions

12-3*5
(12-3)*5
6/2*3
6/(2*3)
-5^2*2
(-5)^2*5

Multiplication is also performed when * is replaced with 
a space. This helps formulas look as in written mathematics): 

3 (8-4) 

***********************
* BUILT-IN FUNCTIONS: *
***********************

Many functions are already implemented in Mathematica: you see
some of them. Try them out. 

Sin[0.1234]
Sqrt[3.0]
Cos[2*Pi]
Sin[Pi/4]
Random[]
N[Sin[Pi/4]]
N[Pi,200] 

N[x] produces a numerical value of x, N[x,1000] produces a numerical 
value of x with 1000 digits. 

Want to see, what functions are predefined which begin with 
"Si" ? Try 

?Si*

You will be given a list of functions. Among them is Sinh. To 
learn more about it, type

?Sinh

***********************
* DEFINING FUNCTIONS: *
***********************

An example explains best to define your own functions:

f[x_]:=x^2-3x + 4

You can evaluate f at a point 5.2 with 

f[5.2]

Also functions of many variables can be defined as in the 
example 

Distance[x_,y_,z_]:=Sqrt[x^2+y^2+z^2]

which computes the length of a vector (x,y,z). To evaluate, 
try 

Distance[0.4,0.5,0.7]

***********************
* PLOTTING FUNCTIONS: *
***********************

Functions of one variable are plotted as follows:

Plot[Exp[-x^2/2],{x,-3,3}] 


Functions of two variables are plotted with 

Plot3D[Exp[-(x^2+y^2)/2],{x,-3,3},{y,-3,3}]

*********************************
* PLOTTING CURVES IN THE PLANE: *
*********************************

To plot a curve in the plane, proceed as in this example:

ParametricPlot[{Cos[3 t],Sin[5*t]},{t,0,2 Pi}]

Curves in three dimensional space are plotted as in the example

Plot3D[{Cos[t](2+Cos[40t]),Sin[40t],Sin[t](2+Cos[40t])},{t,0,2*Pi}]


*********************************
* EXERCICE 1:                   *
*********************************

1) Define two functions f1,f2, which give the two square roots
of the quadratic equation

a x^2 + b x + c == 0

Hint, if you don't remember the formulas by heart, Mathematica can 
give you a hint with 

Solve[a*x^2+b*x+c==0,x]

The functions should work in such a way that for example

f1[1,0,-1]
f2[1,0,-1]

give the two solutions x=1 or x=-1 of the equation  x^2-1 == 0

*********************************
* EXERCICE 2:                   *
*********************************

2) Plot the function x -> Sin[1/x]  for -4<x<4. 
Describe it in words. You have only to write down and submit 
the equation. You are welcome to produce submit a print out. 

