In[1]:=
Now type 5+7 on this prompt and press Enter. You see the expected answer. This shows how you can use Mathematica as a $10 calculator :-) Lets do some more calculations... Try the following:
3^2
What's the answer...
Now try this:
3^100
So now you can see that its a little more than a calcualtor...
Mathematica can do infinite precision math. ( If you don't quite
get what I mean, try calculating 3 raised to power 100 on your
calculator)
But it's much more than just an infinite precision calculator. Try this.... ( type exactly as shown )
NIntegrate[Sin[Sin[x]],{x,0,Pi}]
So you have now calculated the numerical integral for the function sin(sin(x)) between 0 and Pi.
Mathematica has a lot of built in functions including trigonometric functions, exponential functions, special functions like Bessel functions, Airy functions etc.
Now type Quit on the mathematica prompt. You will be thrown back to the unix shell prompt. Once there, type mathematica
Wait until you see a new window emerge on the screen. This is yet another way to use Mathematica. It looks prettier and can do graphics and is the interface ( or Front End) you will be using for most of this class. Now... try everything you did earlier in the Unix shell version of Mathematica and see that it works here too. One note: Now you will have to press Shift and Enter together to get the result of your calculation rather than just Enter
Let's put the graphics to use. Let's start with a simple plot. Try the following:
Plot[Sin[Exp[x]],{x,0,Pi}]
As you would expect, you will see a plot of the function sin(exp(x)) for x between 0 and pi. Let's see that plot again:
Show[%]
What did we do? The '%' sign stands for the output of the last command executed. In this case it was a plot. The Show command takes a graphics object as its argument and.. well.. shows it.
Let's see another plot,
Plot[ Sin[x], {x,0,Pi}]
So now we have plotted the sin function between 0 and pi. What if we wanted to see both the plots together. What we have to do is the following:
a=Plot[Sin[Exp[x]],{x,0,Pi}]
then
b=Plot[ Sin[x], {x,0,Pi}]
and then
Show[a,b]
Now we should see both plots together. Another way to see both plots together is as follows:
Plot[ {Sin[x], Sin[Exp[x]]}, {x,0,Pi} ]
Try plotting some other functions separately and together and play around
with it a little bit.
What if you didn't want your plots on the same graph but side by side. Well,
Show command is our friend again:
Show[GraphicsArray[ {a,b} ] ]
This should show you both graphs side by side. Another thing you can do with Show commands is to change some aspects of the plots you have already drawn. eg. if you wanted to see the plot a only between 0 and pi/2 instead 0 and pi, you would do the following: Show[a,PlotRange->{-1,2}]
By now you have accumulated a lot of stuff on your screen. You can save it for later use. Go to the File menu and choose Save. A dialog box will come up and ask you for a file name ( change it from "Untitled.."to something meaningful to you). This will save your "Notebook" to your home directory ( or to some subdirectory under it if you chose that). The "Notebook" is the "Front End" that you are using right now ( as oppoed to the " Unix shell front end" you were using in the very beginning) . When you save a notebook, you are saving all the text and graphics that's on the screen to a file. You can open that same NoteBook at a later time if you want to use some of the same stuff again. Just remember that when you do open the notebook at a later time, you will have to "remind" Mathematica all the functions and variables you had defined in that notebook. How do you do that? As follows: