Oliver knill, Harvard University, knill@math.harvard.edu, MathS21a, Summer 2008

Welcome to the Mathematica project of Summer 2008! This notebook will be your guide to get started. It also contains the assigment at the very end. If you work on a project, save it frequently and make backups. Have fun! .

Content in a mathematica file is organized as cells. Cells can be evaluated by grabing the bracket to the right, holding down the shift key and hitting return. Try it out in the next cell:

In[1]:=

Out[1]=

After evaluating the cell, an output cell has been added to the input cell. The output cell can be made interactive as in the following example:

In[2]:=

Out[2]=

Lets get started. I suggest you read through the examples and evaluate the ones you are interested in which are hopefully all. If you are unpatient, grab the most outer bracket to the right which contains the entire notebook and evalute it. All the cells will be evaluated.

A calculator

Anything you can do on a graphics calculator you can do with a computer algebra system, only better and more accurately. Here is an exmple to compute a numerical expression

In[3]:=

Out[3]=

It did not compute it numerically and left terms like square roots of integers intact. To get a numerical varlue or a numerical value jor a value with accuracy 200 digits, access the previous expression (called %) and

In[4]:=

Out[4]=

Lets play with this:

In[5]:=

Out[5]=

Or look at the list of prime numbers

In[6]:=

Out[6]=

or binominal expressions

In[7]:=

Out[7]=

Some single variable calculus

One of the most common tasks one does with a computer algebra system is to differentiate and integrate. Here are several ways to write a derivative:

In[8]:=

Out[8]=

In[9]:=

Out[9]=

In[10]:=

Out[10]=

Or integration

In[11]:=

Out[11]=

Here we can manipulate algebraic expressions with the parameter n, the number of derivatives.

In[12]:=

Out[12]=

The derivative of a function gives the rate of change. Here is an animation which illustrates that

In[13]:=

Out[16]=

Here is an experiment which explores the convergence of p-series:

In[17]:=

Out[17]=

A Taylor expansion:

In[18]:=

Out[18]=

But lets move to multivariable calculus!

Graphs

After evaluation of the next cell, you get a graphics object, which you can manipulate with the mouse.

In[19]:=

Out[19]=

As with any command, there are many options, one can explore.

In[20]:=

Out[20]=

Quadrics

Here, we see the deformation from a two sheeted to a one sheeted hyperboloid

In[21]:=

Out[21]=

or from a hyperbolic, to an elliptic paraboloid

In[22]:=

Out[22]=

Parametrized Surfaces

In[23]:=

Out[23]=

Here is an version which can be manipulated:

In[24]:=

Out[24]=

Parametrized Curves

Parametric curves are plotted with the same command than parametrized surfaces. There is only one paremater.

In[25]:=

Out[25]=

In[26]:=

Out[29]=

Polar Curves

In[30]:=

Out[30]=

Knots

In[31]:=

Out[31]=

Contour maps of a function

In[32]:=

Out[32]=

Implicit surfaces

Implicit surfaces are now plotted with CountourPlot. By default, a contour map is drawn.

In[33]:=

Out[33]=

We can specify which contour we want to see by specifying the set of values.

In[34]:=

Out[34]=

Again this can be made into a manipulation object.

In[35]:=

Out[35]=

Second derivative test

The following procedure and example speaks for itself

In[36]:=

Out[37]//TableForm=

x | y | D | f_xx | Type | f |

-2 | 0 | -64 | 0 | saddle | 0 |

-1 | -1 | 32 | -6 | maximum | 2 |

-1 | 1 | 32 | 6 | minimum | -2 |

0 | 0 | -16 | 0 | saddle | 0 |

1 | -1 | 32 | 6 | minimum | -2 |

1 | 1 | 32 | -6 | maximum | 2 |

2 | 0 | -64 | 0 | saddle | 0 |

0 | -2 | -64 | 0 | saddle | 0 |

0 | 2 | -64 | 0 | saddle | 0 |

Lagrange multipliers

mathematica has in general no problems to solve Lagrange problems in with one constraint

In[38]:=

Out[40]=

or two constraints

In[41]:=

Out[44]=

Surface area

Given a parametrized surface r[u, v], we can calculate its area.The following example finds the surface area of the sphere.

In[45]:=

Out[47]=

In the next example, we have a surface, where the integral can not be evaluated symbolically and where we

switch to a numerical computation of the integral with NIntegrate.

In[48]:=

Out[50]=

Vector fields

Plotting vector fields needs an external library. Here is

In[51]:=

Out[51]=

Gradient fields can be plotted directly:

In[52]:=

Out[52]=

In three dimensions, you get an object which you can turn with the mouse:

In[53]:=

Out[53]=

And again there is a gradient field version

In[54]:=

Out[54]=

We all know that gradients are perpendicular to the level curves:

In[55]:=

Out[55]=

Line Integrals

Given a vector field F and a curve r (t), line integrals can be computed with a command like

In[56]:=

Out[58]=

If you wanted to make this into a procedure, you could define

In[59]:=

and then give a vector field and a path as an argument:

In[60]:=

Out[62]=

Flux integrals

In[63]:=

Out[65]=

In the next example, we have a surface, where the integral can not be evaluated symbolically and where we

switch to a numerical computation of the integral with NIntegrate.

In[66]:=

Out[68]=

Greens theorem

The curl of a 2 D vector field is a scalar function.We define a Mathematica procedure which takes a vector field as an argument and returns a function :

In[69]:=

For example:

In[70]:=

Out[70]=

Greens theorem assures that the double integral of curl (F) over a region G is the line integral of F along the boundary.Lets check that : first compute the line integral :

In[71]:=

Out[72]=

Now compute the double integral of the curl of F over the region :

In[73]:=

Out[74]=

These two numbers should agree.To see the error, we ask to give the result with 20 digits :

In[75]:=

Out[75]=

Stokes theorem

The curl of a 3 D vector field is a vector field.We define a Mathematica procedure which takes a vector field as an argument and returns vector field which is the curl.

In[76]:=

For example

In[77]:=

Out[78]=

Stokes theorem assures that the flux of curl (F) through a surface S is the line integral of F along the boundary.Lets check that in a special case where S is the south hemisphere.The boundary of this surfaced is a circle in the xy - plane but note the orientation!

In[79]:=

Out[81]=

Now compute the double integral of the curl of F over the surface.Note that the parametrization is chosen such that the normal vector points outside.We compute the integral numerically :

In[82]:=

Out[86]=

It is your call to see whether the two numbers agree.

Graphics

Software like Mathematica is often also used for doing illustrations in books, articles, reports or the web.Here is an example :

In[87]:=

Out[90]=

This graphics object can be exported in different formats like Tif, Gif, Jpg, PDF or Postscript :

In[91]:=

Out[94]=

Besides polygons, you can use lines, discs or points.

In[96]:=

Out[105]=

Sound

Lets play a 2000 Herz sound for 5 seconds:

In[106]:=

Out[106]=

We can try to manipulate this:

In[107]:=

Out[107]=

Polyhedra

Lets draw a snow cube polyhedron, a semiregular polyedron. With the opacity, we can adjust, how transparent the surface is

In[108]:=

Out[108]=

Here are all 5 regular polyhedra matched into each other

In[109]:=

Out[109]=

Animations

The following animation is a mechanical system. Run the cell and you will see an animated picture. You can turn around the picture while it moves.

In[110]:=

Out[123]=

Chemical Data

There is a large amount of Chemical data available.The first time you use, it it will take some time to process.But once the picture appears you can turn the molecule.

In[124]:=

Out[124]=

If you want to know what data are available, you can try :

In[125]:=

Out[125]=

Here is an example

In[126]:=

Out[126]=

Financial Data

Also financial data are available. Here is a plot of the Dow Jones data:

In[127]:=

Out[127]=

What happend with the DJI since January 1, 2008?

In[128]:=

Out[128]=

What happend with the stock of the company Apple between January 1, 2007 and January 1, 2008?

In[129]:=

Out[129]=

Image manipulation

A graphics can be saved in many file formats. Here is an example

In[130]:=

Out[130]=

We can import the picture back as a raster image.

In[131]:=

Lets darken the picture a bit.

In[132]:=

Out[132]=

Assignment

To get full credit for this Mathematica assignment, you have to hand in :

1) A printout of a parametric surface r (u, v) = (x (u, v), y (u, v), z (u, v)) of your choice.

2) A printout of an implicit surface g (x, y, z) = 0 of your choice.

3) A query for some financial data or some molecule.

4) Compute the arc length of the rurve r[t_] := {t^2, Sin[t^3],t^3}, where t goes from 0 to 1.

5) A printout of a graphics object of your choice, which involves discs, lines, polygons or points.

Your examples should be different from any example which appears in this notebook.

If you find something cool during your experiments, feel free to include it also.In order to work on your project it is a good idea to save this notebook first as a different document, do the assignment directly in that notebook and print out the relevant pages at the very end on a printer.The assignments have to be printed out and turned in the last class.

Oliver Knill, Juli 20, 2008, email: knill@math.harvard.edu