Help with Mathematica
(See bottom of this page for comments directed at specific Phys 2210 Homework assignments!)
Mathematica is an extremely
powerful
software to do analytical and numerical calculations. Its
syntax is fairly simple and its online
help is easy to use. The
University
has a site license for Mathematica
and it is installed on every ITS
computer. You can also install Mathematica on your own computer. Look at the instructions at ITS
site Licensing
The download is large, so please get Mathematica installed on your own machine ASAP, before you need it for a homework!
_______________________
Getting
started
The Mathematica website has
several good tutorials. If you have never used Mathematica, browse the offerings at Mathematica tutorials -
screen broadcasts.
I like the 2-part Hands-on start
to Mathematica series. The How-to
pages have many good examples and are relatively easy to navigate.
In this class we will
frequently use Mathematica to solve differential equations. See the How
to work with differential equations website for examples of how to
do it.
Physicists vs computers
For us the computer is only a
tool. Remember that it can do only
what you teach it to do and what you tell it to do.
Mathematica can do a lot of
abstract
calculations, like integrals, solving differential equations, etc.
But if an indefinite integral
does
not exist or the solution of a differential equation does not exist, it will not be able to come up
with an analytical solutions. It will be able to give you a numerical
solution, but in that case you have to
specify
numerical values for each constants, parameters you have.
Units: Be
consistent!
If you want your result in MKS units, make sure that every parameter you specify is in MKS units. This
is the engineering approach. Physicists often come up with their own "units" for each
problem.
If there is a characteristic length scale in a problem, like the radius of the Earth when
discussing
satelite motion, it's much more convenient to measure
everything in that unit instead
of meters. We'll discuss this further in different applications.
When you get frustrated
If you are new to Mathematica or numerical calculations, you might get overwhelmed and frustrated. This is normal. Take a breath and start again. You are smarter than the computer,
so do not give up. You have to get over the initial barrier but after a while things will get easier and you will find yourself doing a lot of things with Mathematica.
(page modified from Prof. Anna Hasenfratz, CU Boulder)
_____________________________________
Comments specifically for Homework #2:
1) Remember to hit SHIFT at the same time as return to get MMA to evaluate your expression.
2) Functions and commands in MMA always start with capital letters (like Plot[ ] or Sin[ ] or Sqrt[ ] or Pi)
3) The "Help" menu is very useful - go to "Documentation center", and search from there for whatever you're interested in.
Comments specifically for Homework #3:
1) Log[x] is the natural logarithm (what we normally call ln(x) in class)
2) To choose the limits (x and y) in your plot: Plot[f[x],{x,x0,x1},PlotRange -> {{xmin,xmax},{ymin, ymax}}]
3) To define a function, use a syntax like e.g. y[x_,c_] := c x^2
(Note the "underscore" after the variable name on the LEFT side, but not on the RIGHT side - this is how you define a function of variables. The colon before the equal makes it less likely that MMA will do strange things later in your code :-)
4) There's a really cool MMA command that you can use to your advantage in problems like this:
Manipulate[ MMA commands here, {c,cmin, cmax}]
Where "stuff" might be, say, a plot (or whatever) which has buried in it the undefined constant c. What "Manipulate" does is it creates a little slider, which runs from cmin to cmax, and as you slide it, MMA dynamically changes the value of c to be what you pick. E.g,
Manipulate[ Plot[c x^2,{x,0,2},PlotRange->{{0,2},{0,20}}],{c,0,5}]
will let you plot the function cx^2, and c is "at your control". Try it, you'll see how handy it is!