Mathematica in a Nutshell

Mathematica is a computer algebra system. We will use it in two ways. The first is to perform symbolic manipulations to perform explicit calculations. The second is to plot functions, curves, and  surfaces in order to help us visualize the geometric objects which we are studing.

Symbolic Operations

Mathematica attempts to put all inputted mathematical expressions into a standard form. For example, move your pointer to the end of the next line and hold down the shift key and press enter:

100  -  25  +  6

NOTE : 
      Always hold down the shift key and press enter to input 
        expressions into mathematica .

\(TextForm
    \`Mathematica\ keeps\ expressions\ in\ exact\ form . \ For\ example, \ 
    Sqrt[3]\ means\ \@3\ below . \ Go\ to\ the\ end\ of\ the\ line\ and\ press
      \ shift\ and\ enter\ just\ like\ before\ 
      \(\((\ in\ fact, \ do\ this\ after\ each\ colon\ below)\) : \)\)

8 Sqrt[3]  -  3*5

\(TextForm
    \`Do\ the\ same\ below . \ Notice\ that\ the\ following\ computes 
      \((\@3)\)\^5\)

Sqrt[3]^5

Mathematica also manipulates algebraic expressions exactly. The following line expands out the product (2 x - 5) (8 x + 1):

Expand[(2 x  -  5 ) (8 x  +  1)]

If you would like to factor the above then do:

Factor[%]

The % sign tells the Factor command to factor the output of the previous line -- namely, -5 - 38 x + 16 x^2.

\(TextForm
    \`Mathematica\ can\ also\ do\ calculus . \ The\ following\ is\ a\ 
      calculation\ of\ 
      \(\(∂\_□\ 
              \((x\^3 - 5\ y\^2 + Sin[\(x\^2\) z])
                \)\/∂\_□\ x\) : \)\)

D[x^3  -  5 x y ^2  +  Sin[x^2 z], x]

Notice that Sin[x], Cos[x], Tan[x] have their standard meanings (Don't forget the capital letters -- Mathematica is case sensitive -- and arguments to functions should always involve the square brackets [ and ]).

Suppose you want to now plug in y  =  
        12 and x  =  stuff + 1 into the result then type

%  /.  {y  ->  12,  x  ->  stuff + 1}

Similarly, one do integration∫((2  x - 1)/((x^2) - x)) dx :

Integrate[(2 x  -  1)/(x^2  -  x), x]

Definite integrals can also be done .  The following expression computes \(∫\_\(\(-1\)
\)\%8\)(e^(3  x)) dx :

Integrate[E^(3 x), {x, -1, 8}]

Mathematica can also be asked to simplify expressions. Consider the following derivative:

D[x^2/(2 x  -  3)^2, x]

Now simplify the last output:

Simplify[%]

Notice that Simplify does not alter expressions like

Simplify[Sqrt[x^2]]

because of the ambiguity in the choice of sign. If you want to force Mathematica to get rid of the square root, then try

PowerExpand[Sqrt[x^2]]

but you want to make sure that x is nonnegative before doing this command!

Define the following function which computes the area of a circle of radius r:

CircArea[r_]  :=  Pi r^2

(Don't forget the _ after the r and the : before the = as they are very imporant!) Now plug in the value 9 for x as follows:

CircArea[9]

We can now compute the derivative of CircArea via:

D[CircArea[r], r]

Linear Algebraic Operations

In Math 563,  
    we will need to manipulate vector valued functions .  The vector
       {3, -2, 1} in (R^3) is denoted by :

{3,  -2,  1}

Notice that we can multiply vectors by a scalar and add them:

y {2  x  -  3,  x^3  +  2 ,  3}  + {1, 1, 2}

You can take the dot (or scalar) product of two vectors as follows:

{2, 1, x}  .  {8, y, 3}

The cross (or vector) product of {2,3,4} and  {-1,2,9} is:

Cross[{2, 3, 4}, {-1, 2, 9}]

\(TextForm
    \`We\ can\ define\ a\ function\ Norm[v]\ which\ computes\ the\ length\ of
          \ the\ vector\ v\ using\ the\ formula\  | v | \  = 
      \(\@\(v . v\)\) as\ \(follows : \)\)

Norm[v_]  := Sqrt[ v  .  v]

To compute the norm of a vector {3,-2,1}, do the following:

Norm[{3, -2, 1}]

Matrix operations are similar to vector operation. Multiplication and addition of matrices can be done as follows:

6 {{x, x^2}, {x^3, x^4}}  .  {{2, 3}, {7, 10}}  + 
       {{Sin[x], Cos[x]}, {-Cos[x], Sin[x]}}

Denote the matrix above by A:

A  =  %

To obtain entry number (2,1) of this matrix, write

A[[2, 1]]

Plotting Curves and Surfaces

Consider the circle of radius 1 defined parametrically by the equation { Cos[t],  Sin[t]}. We can plot this via:

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

To superimpose the equation for its involute which we also plot from t=0,...,2 Pi, we do:

ParametricPlot[{{ Cos[t],   Sin[t]}, {Cos[t]  +  t Sin[t], 
          Sin[t] - t Cos[t]}}, {t, 0, 2 Pi}]

To plot a helix in (R^3),  
    from t = -2 Pi  ...  2 Pi,  do the following :

ParametricPlot3D[{3 Cos[t],  3 Sin[t],   t}, {t, -2 Pi,  
        2 Pi}]

\(TextForm
    \`To\ plot\ a\ surface\ in\ \(R\^3\) given\ in\ parametric\ form, \ 
    consider\ the\ \(hyperboloid : \)\)

ParametricPlot3D[{ Cosh[u] Cos[v],  Cosh[u] Sin[v],  
        2  Sinh[u]}, {u, -2, 2}, {v, 0, 2  Pi}]

A torus of revolution looks like:

ParametricPlot3D[{ (5  +  2 Cos[u])  Cos[v],  
        (5  +  2 Cos[u])  Sin[v],  2  Sin[u]}, {u, 0, 2 Pi}, {v, 
        0, 2  Pi}]

Numerical Operations

To obtain a numerical value of an expression, try something like

N[Sqrt[2]]

or to specify 20 digit accuracy type

N[Sqrt[2], 20]

To solve the polynomial equation numerically -- notice that the symbol I is ((-1)^(1/□))

NSolve[x^6  +  3 x^2  -  4 x  -  16  ==  0, x]

To solve a system of ordinary differential equations with given boundary conditions numerically, consider the following system (the Lorenz equations):

\(NDSolve[{\(x'\)[t]\  == \ \(-3\)\ \((x[t]\  - \ y[t])\), 

        		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
        \(y'\)[t]\  == \ \(-x[t]\)\ z[t]\  + \ 26.5\ x[t]\  - \ y[t], 

        \ 		\ \ \ \ \ \ \ \ \ \ \ \ \ \ 
        \(z'\)[t]\  == \ x[t]\ y[t]\  - \ z[t], 

        		\ \ \ \ \ \ \ \ \ \ \ \ \ \ x[0]\  == \ z[0]\  == \ 0, \ 
        y[0\ ]\  == \ 1}, 

      	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {x, y, z}, {t, 0, 20}, 
      MaxSteps\  -> \ 3000]\)

The MaxSteps -> 3000 is the number of steps that the interval [0,20] will be broken into in order to perform the numerics. The default value of MaxSteps (which occurs when MaxSteps is unspecified) is 500.

To plot the result, do

ParametricPlot3D[Evaluate[{x[t], y[t], z[t]}  /.  %],  {t, 0, 20},  
      PlotPoints  ->  1000]

where PlotPoints -> 1000 specifies the number of points to plot.