[an error occurred while processing this directive]

Notes on Mathematica from Seminar on 11/11/97

Dan Lawrence, Physics Department, Purdue University


Starting up.

To open mathematica, type "mathematica" at a login prompt
(i.e. Bragg:> mathematica [return])

Use the Menu bar to save, open, print, ... files, format cells, etc.

For help, your best two places are:
1) Open the Function Browser from help menu
2) Look at the book Mathematica by Stephen Wolfram, it is on reserve
in the physics library.

A sample problem - The Pendulum

Mathematica can quickly do algebra and calculus problems

[Graphics:pendulumgr2.gif][Graphics:pendulumgr1.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr3.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr4.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr5.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr6.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr7.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr8.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr9.gif]

Mathematica can do both partial and full derivatives. Dt is a total derivative, and D is a partial derivative.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr10.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr11.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr12.gif]

Simplify is a command that combines terms algebraically.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr13.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr14.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr15.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr16.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr17.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr18.gif]

Sometimes Mathematica gives more than is needed. Here we take out the term we know doesn't need to be there by hand.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr19.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr20.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr21.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr22.gif]

The term {t, 2} in the above output means to take the second total derivative with respect to the variable t. The symbol "%" means to use the last output given. So below, "%" refers to Out[12]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr23.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr24.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr25.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr26.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr27.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr28.gif]

NDSolve is a function which takes a differential equation and some initial conditions, and numerically solves the equation. The output is an InterpolatingFunction. An InterpolatingFunction represents an approximate function whose values are found by interpolation. We can Evaluate the function at some time t to find &thgr;[t].
The symbol "/." reads "ReplaceAll with". So Evaluate[&thgr;[t] /. diff] would give us &thgr; at time t using the function diff.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr29.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr30.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr31.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr32.gif]

We can also write the differential equation in the more familiar form using primes.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr33.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr34.gif]

We can use the solutions to plot the position, velocity, and acceleration vs. time. Plot is a function which plots the given equation over a specified range.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr35.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr36.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr37.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr38.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr39.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr40.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr41.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr42.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr43.gif]

Mathematica can assign complicated functions to one variable to simplify what one needs to write.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr44.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr45.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr46.gif]

We can use Mathematica to quickly create lists of numbers, and to plot them. Table evaluates a function at given intervals, and stores the numbers in a list. Sometimes Mathematica's output contains extra parentheses. Flatten will remove them. We can take individual elements of a list or matrix by using List[[element]]. ListPlot is a function which takes a list of numbers and plots a point for each one.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr49.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr52.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr55.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr56.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr57.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr58.gif]

We can go back and let our differential equation be a function of several variables, length l, and starting angle &agr;. The symbol ":=" means define this function as follows. Note the "_" following all independent variables.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr59.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr60.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr61.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr62.gif]

We can find the period by looking at the 1st two minimums of the above plot. FindMinimum finds the minimum of a function around a given point.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr63.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr64.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr65.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr66.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr67.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr68.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr69.gif]

We can write a short program to find the period for varying length l. The output of Table will be a list of values of the periods. The Plot term will also give a group of figures. We can collapse the cells into one cell, and Mathematica can animate then sequentially.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr70.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr81.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr82.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr83.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr84.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr85.gif]

We can do the same for fixed l, but vary the starting angle &agr;.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr86.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr102.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr103.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr104.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr105.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr106.gif]

Other Examples

Often in quantum mechanics, we work with complicated special functions. Mathematica can easily work with these. For example, one can plot a Bessel function where the independent variable is the order of the function.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr107.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr108.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr109.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr110.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr111.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr112.gif]

Mathematica can quickly work with matrices, combining, inverting, etc. both symbolically and numerically. Below, M is a matrix one obtains when trying to find the conductance of a ring shaped conductor. Without going through this in detail, you can see how Mathematica inverts it, adds and subtract elements, and can pull out elements to plot.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr113.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr114.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr115.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr116.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr119.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr120.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr121.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr124.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr125.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr126.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr127.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr128.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr129.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr130.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr131.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr132.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr133.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr134.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr135.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr136.gif]

Mathematica can also give series expansions for complicated functions.

[Graphics:pendulumgr2.gif][Graphics:pendulumgr137.gif]

[Graphics:pendulumgr2.gif][Graphics:pendulumgr138.gif]
[Graphics:pendulumgr2.gif][Graphics:pendulumgr139.gif]


[an error occurred while processing this directive]