Maple and
Mathematica
Maple and Mathematica
are two very powerful packages for symbolic and numeric computing as
well as for visualization. In my personal opinion Matlab is more
convenient for numerical computation but I use the CAS-features in
Maple and Mathematica fairly often. CAS stands for Computer Algebra
System and here is a Wikipedia-link
to a list of such systems.
The only reasons for this assignment is to inform you about the
existence of these packages (not many students seem to have used them)
and for you to try some graphics commands. My intention is not for you
to become an expert (nor am I one myself :-)
You can probably start the programs from the menu in the window system,
if not you can start them by typing the following in a terminal window:
To start Maple: /chalmers/sw/sup64/maple-18.01/bin/xmaple
To start Mathematica: /chalmers/sw/sup64/mathematica-9.0.1/bin/mathematica
Three important notes:
- When you type a command in Mathematica you need to press
shift-enter to execute it, enter by itself just makes it possible for
you to continue on the next line.
- There seem to be a glitch in the Maple-graphics (at least on my
machine, probaly an old driver for the GPU).
- You may have to load
packages in Maple (see the documentation), perhaps typing something
like with(plots):
(the colon suppresses output). If you miss a package, nothing much will
happen when you give the plot-command.
Now to the problems. Both packages have huge help-systems. In Maple
choose Maple Help from the Help-menu and then have a look at Graphics. In Mathematica, choose Documentation Center from the Help-menu, then look at Visualization and Graphics.
Visualize the follwing
objects in Mathematica (Maple is optional).
- Read the first few lines (at least) from the Wikipedia
article about catastrophe theory. Then visualize the so-called
swallowtail catastrophe surface. Use the following parametrization (u
and v are the parameters):
x(u, v) = 3 v4 + u v2, y(u, v) = - 4 v3
- 2uv, z(u, v) = u. You have to choose suitable ranges for u and v.
- Animate the sequence of (complex) roots to the equation x11
+ p x5 = 2+ I (where I^2 = -1) and where p
= 0:0.2:20 to use Matlab-notation.
Hint:
this statement will produce a list of the eleven lists consisting of
real- and imaginary parts of the roots.
{Re@#, Im@#} & /@ (x /.
Solve[x^11 + p x^5 == 2 + I]). For a short explanation see the
bottom of this page.
- You
have four particles (point masses) in space. The masses are 1, 2,
3 and 4 and the corresponding positions are (0, 0, 0), (1, 0, 0), (0,
1, 0) and (0, 0, 1) respectively. Visualize the gravitational
potential (see below) when x, y and z varies in [-2, 2] by plotting the
level surfaces (in 3D) for the levels -6 and -12. Experiment with the Mesh, AxesLabel and ContourStyle parameters.
Explanation of the hint: Say
we have a second order polynomial (so I don't have to write so much)
with the roots (for a fixed p) 2 + 3i and -7+11i (using
Matlab-notation). The Solve-command produces a list of lists of
so-called rules: {{x -> 2+3i}, {x -> -7+11i}}. lhs -> rhs
represents a rule that transforms lhs to rhs.
/. is the ReplaceAll-command, expr /. rules applies a rule or list of
rules in an attempt to transform each subpart of an expression expr. So
x /. {{x -> 2+3i}, {x -> -7+11i}} becomes the list of the roots:
{2+3i, -7+11i}.
@
produces an operator form (prefix notation) of a function. One can
write like this, for example: Sqrt@ 4 and get the answer 2 (it is more standard to write Sqrt[argument], but the operator version is needed in the hint).
#, called slot, represents the first argument supplied to a function and & is used to define the body of a function, body &, so for example: (Sin[#] Cos[#]) &[6] becomes Sin[6] Cos[6]. func = (#^2) & followed by func[5] produces 25.
f /@ expr, map, applies the function f to each element in expr, so for example, Sin /@ {1, 2, 3} becomes {Sin[1], Sin[2], Sin[3]}.
Now suppose you have two functions F[x] and G[x], then {F@#, G@#} & /@ {r1, r2} produces {{F[r1], G[r1]}, {F[r2], G[r2]}} which is the final expression if you change F, G to Re, Im and let {r1, r2} be the list of roots.
If you want more help you can search the Mathematica documentation for symbols like, /., @ etc. or read the free pdf-file, Core Language, 357 pages (here is a page of free manuals). here is the equivalent page for Maple.
Definition of the gravitational potential for point masses. Suppose there are n masses mk, k = 1, .., n with positions rk. (each rk is a 3D-point). Given the position r (in 3D) we define the potential V(r) as:
V(r) = - (m1 / | r - r1 | + ... + mn / | r - rn |)
where | | denotes the ordinary Euclidean vector length.