[Graphics:Images/name.bmp]

[Graphics:Images/title.gif]



Mathematica
is an extremely powerful system for doing mathematics by computer. There are books and tutorials you can use to learn as much as you want to know about it, but you don't need to know very much at all to get it working for you.

Find a computer with Mathematica on it. Beware: SIPA lab computers do not have Mathematica, but all computers in the Lehman Library computer cluster do. (You can also find it in the labs at 213 Butler and 251 Mudd Engineering Terrace).

To start, select Programs, then Quantitative Apps., Mathematica, then Mathematica 5.2.

Run through the various exercises below, and see if you get what I get.

You enter the things that follow the In[ ] tags, and Mathematica responds with the things following the Out[ ] tags.

To input a new cell,  get a horizontal black line by clicking the cursor  after the cell you want your input to follow---then start typing.  When you've finished entering data, hit the Shift-Return keys together to record it.

We can do arithmetic:

[Graphics:Images/index_gr_1.gif]
[Graphics:Images/index_gr_2.gif]
[Graphics:Images/index_gr_3.gif]
[Graphics:Images/index_gr_4.gif]

You can get a precise numerical answer by applying the function N[ ]  to it:

[Graphics:Images/index_gr_5.gif]
[Graphics:Images/index_gr_6.gif]

We can plot functions of one variable:

The Plot[  ] command does the plotting. You give it the function you want plotted, the range of x values you want it plotted for, and tell it where you want the axes origin to be:

[Graphics:Images/index_gr_7.gif]

[Graphics:Images/index_gr_8.gif]

[Graphics:Images/index_gr_9.gif]
[Graphics:Images/index_gr_10.gif]

[Graphics:Images/index_gr_11.gif]

[Graphics:Images/index_gr_12.gif]

You don't always need the AxesOrigin command. Sometimes Mathematica guesses correctly:

[Graphics:Images/index_gr_13.gif]

[Graphics:Images/index_gr_14.gif]

[Graphics:Images/index_gr_15.gif]

You can go to  Help to find a range of commands and options. Or, to find a description of any command, just type a question mark ? followed by the name of the command

[Graphics:Images/index_gr_16.gif]
[Graphics:Images/index_gr_17.gif]
[Graphics:Images/index_gr_18.gif]
[Graphics:Images/index_gr_19.gif]

We can plot functions of two variables:

Suppose we have the function of two variables , z= f[x,y], where
    z = x^2+3*x*y +y^2
To obtain a 3-dimensional plot of this relationship, use the Plot3D command.

[Graphics:Images/index_gr_20.gif]
[Graphics:Images/index_gr_21.gif]

Here's how it works

[Graphics:Images/index_gr_22.gif]

[Graphics:Images/index_gr_23.gif]

[Graphics:Images/index_gr_24.gif]

Another kind of plotting uses the command "ContourPlot".

[Graphics:Images/index_gr_25.gif]
[Graphics:Images/index_gr_26.gif]

This command plots the level curves of a function of 2 variables in the two-dimensional plane. Indifference curves, isoquants and other "iso-entities" are all level curves of functions.

Suppose, for example, the utility function is

                 U= x^(1/2)*y^(1/2)
    
To plot some level curves of this function,  you supply the function, the range of x-values and the range of y-values. Here, x goes from 0 to 10 , and so does y.

[Graphics:Images/index_gr_27.gif]

[Graphics:Images/index_gr_28.gif]

[Graphics:Images/index_gr_29.gif]

To get rid of the shading and see just the curves, add the option  ContourShading->False, as below:

[Graphics:Images/index_gr_30.gif]

[Graphics:Images/index_gr_31.gif]

[Graphics:Images/index_gr_32.gif]

To get just one specific contour --- say the one that keeps the value of the function at 5  --- add the Contours option as follows

[Graphics:Images/index_gr_33.gif]

[Graphics:Images/index_gr_34.gif]

[Graphics:Images/index_gr_35.gif]

To get two or more, just add them to the list in the Contours argument.

[Graphics:Images/index_gr_36.gif]

[Graphics:Images/index_gr_37.gif]

[Graphics:Images/index_gr_38.gif]

We can overlay different plots:

Let's say we want to graph a straight line
            y = -5*x + 20
and the level curves of a utility function
            U = x^(1/2)*y^(1/2)
on the same set of axes.

First, assign the name "line" to the plot of the line:

[Graphics:Images/index_gr_39.gif]
[Graphics:Images/index_gr_40.gif]

[Graphics:Images/index_gr_41.gif]

[Graphics:Images/index_gr_42.gif]

Then assign the name "curves" to the level curves:

[Graphics:Images/index_gr_43.gif]

[Graphics:Images/index_gr_44.gif]

[Graphics:Images/index_gr_45.gif]

To superimpose them, you can put them both in a  Show[ ]  commmand

[Graphics:Images/index_gr_46.gif]
[Graphics:Images/index_gr_47.gif]

See?

[Graphics:Images/index_gr_48.gif]

[Graphics:Images/index_gr_49.gif]

[Graphics:Images/index_gr_50.gif]

We can solve equations

Suppose you want to solve the following equation for the variable y:
        
                a*y^2  = b/x

You can use the Solve command:

[Graphics:Images/index_gr_51.gif]
[Graphics:Images/index_gr_52.gif]

To apply it, just supply the equation to be solved  with a double equal sign, then follow that with the variable you want to solve for.

Beware!

In Mathematica, single equal signs, "=", are used for assignment. So if you write x=3y+6, Mathemtica will think you mean variable x stands for 3y+6, and any time you use x it will substitute that value. This is not what you want---believe me. So
  1. always use double equal signs "==" in equations and
  2. if you do mess up, you must "clear" any values you may have assigned to variables. To clear variables x, y and z, just use the command Clear[x,y,z].
It is not a bad idea to "clear" variable names before using Solve[], just in case you've accidently assigned a variable some value somewhere else in the notebook---because Mathematica will remember.

Let's solve a simple equation.


[Graphics:Images/index_gr_53.gif]
[Graphics:Images/index_gr_54.gif]

Sometimes there are multiple solutions. Solve will give you all it can find. Remember the quadratic formula?

[Graphics:Images/index_gr_55.gif]
[Graphics:Images/index_gr_56.gif]

Beware: Sometimes it is hard to see the minus sign out in front. Can you see it in this next one?

[Graphics:Images/index_gr_57.gif]
[Graphics:Images/index_gr_58.gif]

To solve two equations in two unknowns, just put  both equations (with double equal signs), separated by a comma , inside braces {  } and specify the variables to solve for.

For example, so solve the two equations
                     y/x = 15
                    x+y =25
for the variables x and y, do this:

[Graphics:Images/index_gr_59.gif]
[Graphics:Images/index_gr_60.gif]

You can keep adding more equations, too.

We can do calculus

To find the derivative of a function, use the command D[ ]

[Graphics:Images/index_gr_61.gif]
[Graphics:Images/index_gr_62.gif]

For example,

[Graphics:Images/index_gr_63.gif]
[Graphics:Images/index_gr_64.gif]
[Graphics:Images/index_gr_65.gif]
[Graphics:Images/index_gr_66.gif]

To find integrals, use Integrate

[Graphics:Images/index_gr_67.gif]
[Graphics:Images/index_gr_68.gif]

For example,

[Graphics:Images/index_gr_69.gif]
[Graphics:Images/index_gr_70.gif]

Optimization

To find the value of x that maximizes or minimizes  some function one can often take the derivative,  set it equal to zero, and solve for x. Mathematica can help with that.

For example, to find the value of x which maximizes
        -3*x^2 + 2*x + 4
Combine Solve[ ]  and D[ ] like this:

[Graphics:Images/index_gr_71.gif]
[Graphics:Images/index_gr_72.gif]

To verify if this is correct, we can plot the function and take a look:

[Graphics:Images/index_gr_73.gif]

[Graphics:Images/index_gr_74.gif]

[Graphics:Images/index_gr_75.gif]

Looks about right.

Do These Problems on Your Own

  1.   Solve for   y:       [Graphics:Images/index_gr_76.gif]  [Graphics:Images/index_gr_77.gif]  = 1
  2. Look up the definition of the command  named: Sum
  3. Plot the function   y = 40x -10  for values of x between zero and 20.
  4. Solve the two linear equations for x and y:
            
          ax+by=0
            cx+dy=e
  5. Superimpose the graph of  y=x^2+ 4  on the graph of  y = 15x + 5. Let x take on values between zero and 20.

For More ...

Start with Mathematica's built-in tutorial: just click Help->Tutorial.

Then explore the tutorials by D' Andria and Withoff at http://library.wolfram.com/infocenter/Conferences/300/