261 Mathematica Session 1

Congratulations, you successfully loaded the first notebook.

Be sure to switch control of the keyboard and mouse regularly, so that you and your partner can be equally frustrated

Overview

Mathematica Short Cuts

Your job will be to create and evaluate a few "cells".  There are different kinds of cells, e.g. this one is a text cell.
There are also input cells and output cells.  The basic interaction is to submit an input cell and wait for an output cell.
To create an input cell, move the cursor until it goes horizontal and click; then type.  Feel free to edit this notebook.
To evaluate, type "Shift+Enter".  Note: the cursor can be anywhere in the cell; no need to move to the end of the expression.
Or .. use the Enter key at the far right (on the numeric keypad) to evaluate an expression -- no need to hold down Shift for that one.
Here are a few expressions you can evaluate; create more of your own!

2+5

5/7 + 11/13

Note how Mathematica does not use decimals unless you use them first:

Sin[1]

Sqrt[2.0]

And note it is happy to work with symbolic expressions:

4+x - 3 x

There are functions which operate on symbolic expressions, e.g.

Expand[(1+x)^10]

Or

Factor[1+2x +x^2]

Keyboard Copy and Paste.  Whenever possible, use the Copy and Paste functions to save time but also to cut down on errors (for example, when using a function found in the Help Browser).  Ctrl-c and Ctrl-v are a convenient shortcut to using
the menu versions of Copy and Paste.  (Ctrl-x is Cut.)

Command completion! This is activated by Ctrl-k (under Windows; alt-K under Linux). If you start typing a function and then press Ctrl-k, a pop-up menu will show all of the (loaded) Mathematica commands that start with the letters you've typed.  You can select among the choices to avoiding typing (and misspelling) the function name. 
Try seeing how many functions start with "Sin", i.e. type Sin ctrl-K

Referring to previous results :  Use % to refer to the last result and %10 to refer to the result Out[10].  For example :

5^2

Sqrt[%]

Many kinds of brackets

There are three kinds of brackets we will use all the time.  Round brackets are used to group terms together:

3*(1-9)

Square brackets are the syntatic clue that we are using a function:

Sin[π/4]

"Squiggly" braces {} are used to make lists of things.  More on that below.

mylist = {a, b, {"qwerty","dvorak"},Sin[π/6]}

The Many faces of equality

There are at least three kinds of "equals" signs.
The single kind is used to assign a value to a symbol, which can then be used in other expressions.

q = (1 + Sqrt[5])/2

q^2 -q-1//Simplify

The double equals is the relational operator used to make logical propositions, e.g.

a==a

1==2

myeqn = x^2-x-1==0

Solve[myeqn]

Palettes

Under the "Palettes" menu you will find the "Basic Math Assistant" which lets you type at Mathematica using calculator buttons,
 and provides templates for how to use various useful functions.
   1. Try calculating (27^(1/3)) using the Basic calculator.
   2. Use the "Documentation" function to learn about the "N" function, and then find the first 1000 digits of π
   3. Using the calculator's Advanced tab, compute the indefinite integral of ArcSin[x]
   4. How about the definite integral of ArcSin[x] between 0 and 1?
   5. Under the Basic Commands section choose the "y=x" tab and use Solve[] to solve the quadratic x^2 -3x -4==0.
   6. Use the "2D" to find Plot[] and then plot the function sin(x)/x from -10 to 10.

Some Homework Related Mathematica Stuff

Vectors with Mathematica

In Mathematica a vector is just a list of its components.  Let's define two specific vectors by evaluating the following cells.  Note that the use of curly brackets

v1 = {1,2,3}

v2 = {2,3,4}

Here are some of the things you can now compute:

v1 + v2

Dot[v1,v2]

Cross[v1,v2]

Note that Mathematica is quite content to work with symbols in place of actual numbers:

a = {Ax,Ay,Az}

b = {Bx,By,Bz}

Dot[a,b]

Here is how we can show that A ∘ (A × B) = 0 :

V = Dot[a,Cross[a,b]]

This may not immediately look like zero, but it is.  We just have to tell Mathematica to simplify:

Simplify[V]

Here is an exercise you can try: use Mathematica to prove the vector identity
    a × (b × c) =  b (a ∘ c) - c (a ∘ b).   
Try it first on your own before opening up the solution cell below.

Solution

c = {Cx,Cy,Cz}

Cross[a,Cross[b,c]] - Dot[a,c]*b+Dot[a,b]*c

Simplify[%]

Plotting Functions

Time and time again we will want to plot functions. As you've seen above using the palette, the syntax is:

Plot[Sin[x],{x,0,6 Pi}]

Your job: plot Sinh[x] and Cosh[x] together, as in BTM figure 1.3

HOMEWORK PROBLEM

BTM 1.5.2 asks you to “analyze” this function:

(x^2+x-6)/(4+Cosh[x])

By “analyze” we mean: find any zeroes, find any poles, decide what the behavior is as |x| becomes large, and 
then make a sketch of the function incorporating these features.  Usually we do this “by hand”. But here ...
(a) Factor[] the numerator to find any zeroes.  (b) Given the plot of Cosh above, decide if there is any value
of x for which Cosh[x] is -4 (which would give a singularity).  (You might also ask for the ArcCosh of -4.0)
(c) Again consulting the plot of Cosh, decide how the function behaves at plus and minus infinity, and (d) make
a Plot[] along the lines of BTM figure 1.7.  For the homework, you may choose to print this plot, but a hand-drawn
sketch is just fine too.

Printing

If you want to print something out, you'll need to set up your printer.  From the Windows "Start" menu, navigate through
the control panel to the printers section, and choose "Add a Printer".  The one you want is under Physics, and is called Smith1011S.

Calculus

To take a derivative:

D[Sinh[x],x]

Now think of an ugly one and try it.  In particular, you can cross-check the BTM homework, which asks for the derivatives of, e.g.

Sin[x^3+2]
Tan[x]^3
ArcTanh[x]

Or to integrate (indefinite):

Integrate[Sin[x],x]

With definite limits:

Integrate[Exp[-x],{x,0,3}]

Try it with limits from 0 to Infinity.
And finally, here is a game--- invent a truly horrible integrand, and either be impressed that Mathematica can find the integral, or be impressed with yourself for stumping the computer.