Multivariable calculus Computer algebra Project

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]:=

"lab_1.gif"

Out[1]=

"lab_2.gif"

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]:=

"lab_3.gif"

Out[2]=

"lab_4.gif"

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]:=

"lab_5.gif"

Out[3]=

"lab_6.gif"

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]:=

"lab_7.gif"

Out[4]=

"lab_8.gif"

Lets play with this:

In[5]:=

"lab_9.gif"

Out[5]=

"lab_10.gif"

Or look at the list of prime numbers

In[6]:=

"lab_11.gif"

Out[6]=

"lab_12.gif"

or binominal expressions

In[7]:=

"lab_13.gif"

Out[7]=

"lab_14.gif"

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]:=

"lab_15.gif"

Out[8]=

"lab_16.gif"

In[9]:=

"lab_17.gif"

Out[9]=

"lab_18.gif"

In[10]:=

"lab_19.gif"

Out[10]=

"lab_20.gif"

Or integration

In[11]:=

"lab_21.gif"

Out[11]=

"lab_22.gif"

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

In[12]:=

"lab_23.gif"

Out[12]=

"lab_24.gif"

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

In[13]:=

"lab_25.gif"

Out[16]=

"lab_26.gif"

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

In[17]:=

"lab_27.gif"

Out[17]=

"lab_28.gif"

A Taylor expansion:

In[18]:=

"lab_29.gif"

Out[18]=

"lab_30.gif"

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]:=

"lab_31.gif"

Out[19]=

"lab_32.gif"

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

In[20]:=

"lab_33.gif"

Out[20]=

"lab_34.gif"

Quadrics

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

In[21]:=

"lab_35.gif"

Out[21]=

"lab_36.gif"

or from a hyperbolic, to an elliptic paraboloid

In[22]:=

"lab_37.gif"

Out[22]=

"lab_38.gif"

Parametrized Surfaces

In[23]:=

"lab_39.gif"

Out[23]=

"lab_40.gif"

Here is an version which can be manipulated:

In[24]:=

"lab_41.gif"

Out[24]=

"lab_42.gif"

Parametrized Curves

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

In[25]:=

"lab_43.gif"

Out[25]=

"lab_44.gif"

In[26]:=

"lab_45.gif"

Out[29]=

"lab_46.gif"

Polar Curves

In[30]:=

"lab_47.gif"

Out[30]=

"lab_48.gif"

Knots

In[31]:=

"lab_49.gif"

Out[31]=

"lab_50.gif"

Contour maps of a function

In[32]:=

"lab_51.gif"

Out[32]=

"lab_52.gif"

Implicit surfaces

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

In[33]:=

"lab_53.gif"

Out[33]=

"lab_54.gif"

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

In[34]:=

"lab_55.gif"

Out[34]=

"lab_56.gif"

Again this can be made into a manipulation object.

In[35]:=

"lab_57.gif"

Out[35]=

"lab_58.gif"

Second derivative test

The following procedure and example speaks for itself

In[36]:=

"lab_59.gif"

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]:=

"lab_60.gif"

Out[40]=

"lab_61.gif"

or two constraints

In[41]:=

"lab_62.gif"

Out[44]=

"lab_63.gif"

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]:=

"lab_64.gif"

Out[47]=

"lab_65.gif"

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]:=

"lab_66.gif"

Out[50]=

"lab_67.gif"

Vector fields

Plotting vector fields needs an external library. Here is

In[51]:=

"lab_68.gif"

"lab_69.gif"

Out[51]=

"lab_70.gif"

Gradient fields can be plotted directly:

In[52]:=

"lab_71.gif"

Out[52]=

Graphics:None

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

In[53]:=

"lab_73.gif"

Out[53]=

"lab_74.gif"

And again there is a gradient field version

In[54]:=

"lab_75.gif"

Out[54]=

"lab_76.gif"

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

In[55]:=

"lab_77.gif"

Out[55]=

"lab_78.gif"

Line Integrals

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

In[56]:=

"lab_79.gif"

Out[58]=

"lab_80.gif"

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

In[59]:=

"lab_81.gif"

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

In[60]:=

"lab_82.gif"

Out[62]=

"lab_83.gif"

Flux integrals

"lab_84.gif"

In[63]:=

"lab_85.gif"

Out[65]=

"lab_86.gif"

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]:=

"lab_87.gif"

Out[68]=

"lab_88.gif"

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]:=

"lab_89.gif"

For example:

In[70]:=

"lab_90.gif"

Out[70]=

"lab_91.gif"

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]:=

"lab_92.gif"

Out[72]=

"lab_93.gif"

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

In[73]:=

"lab_94.gif"

Out[74]=

"lab_95.gif"

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

In[75]:=

"lab_96.gif"

Out[75]=

"lab_97.gif"

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]:=

"lab_98.gif"


For example

In[77]:=

"lab_99.gif"

Out[78]=

"lab_100.gif"

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]:=

"lab_101.gif"

Out[81]=

"lab_102.gif"

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]:=

"lab_103.gif"

Out[86]=

"lab_104.gif"

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]:=

"lab_105.gif"

Out[90]=

"lab_106.gif"

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

In[91]:=

"lab_107.gif"

Out[94]=

"lab_108.gif"

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

In[96]:=

"lab_109.gif"

Out[105]=

"lab_110.gif"

Sound

Lets play a 2000 Herz sound for 5 seconds:

In[106]:=

"lab_111.gif"

Out[106]=

"lab_112.gif"

We can try to manipulate this:

In[107]:=

"lab_113.gif"

Out[107]=

"lab_114.gif"

Polyhedra

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

In[108]:=

"lab_115.gif"

Out[108]=

"lab_116.gif"

Here are all 5 regular polyhedra matched into each other

In[109]:=

"lab_117.gif"

Out[109]=

"lab_118.gif"

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]:=

"lab_119.gif"

Out[123]=

"lab_120.gif"

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]:=

"lab_121.gif"

Out[124]=

"lab_122.gif"

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

In[125]:=

"lab_123.gif"

Out[125]=

"lab_124.gif"

Here is an example

In[126]:=

"lab_125.gif"

Out[126]=

"lab_126.gif"

Financial Data

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

In[127]:=

"lab_127.gif"

Out[127]=

"lab_128.gif"

What happend with the DJI since January 1, 2008?

In[128]:=

"lab_129.gif"

Out[128]=

"lab_130.gif"

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

In[129]:=

"lab_131.gif"

Out[129]=

"lab_132.gif"

Image manipulation

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

In[130]:=

"lab_133.gif"

Out[130]=

"lab_134.gif"

We can import the picture back as a raster image.

In[131]:=

"lab_135.gif"

Lets darken the picture a bit.

In[132]:=

"lab_136.gif"

Out[132]=

"lab_137.gif"

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

Spikey Created with Wolfram Mathematica 6