Jon's Mathematica Info & Examples 9/7/99
Some general tips on getting along with Mathematica
-
Capitalize all commands and use square brackets around their arguments
(e.g., Factor[x^2+2x+1]).
-
Use only parentheses as grouping symbols in your expressions -- Mathematica
reserves brackets and braces for other purposes.
-
Press Shift-Enter, not just Enter, when you want Mathematica to
evaluate an expression.
Some things Mathematica can do
Normal calculator functions and lots more:
-
2+2 gives 4.
-
Sqrt[2]^4 gives the square
root of 2 to the fourth power, or 4.
-
Sin[Pi/2] gives 1, the sine
of /2.
-
(2+I)*(3-I) multiplies the
imaginary numbers 2+i and 3-i.
-
ArcCos[1/2] computes the
inverse cosine of 1/2 (as an exact value).
-
Tanh[Log[2]] computes the
hyperbolic tangent of the natural logarithm of 2.
-
N[Sqrt[2],20] gives the
square root of 2 to 20 decimal places.
-
N[E^4.1,15] gives the value
of e4.1 to 15 decimal places.
-
Expand[(x+2)(x+3)(x-7)(x-1)]
produces 42 - 13 x - 27 x2
- 3 x3 + x4.
-
Factor[x^3+3x^2-4x-12] produces
(-2
+ x)(2 + x)(3 + x).
-
Solve[x^2-4==0,x] solves
the equation x2-4=0 for x.
-
FactorInteger[2434500] produces
{{2,
2}, {3, 2}, {5, 3}, {541, 1}} meaning 22, 32,
53, and 541 are the factors of 2434500.
-
PrimeQ[5757] gives False
because 5757 is not prime.
Graph functions:
-
Plot[Sin[3x]+Cos[5x],{x,0,20}]
produces a graph of the function for x values from 0 to 20.
-
Plot[Sin[3x],{x,0,20},PlotStyle
-> RGBColor[1,0,0]] produces a graph in red.
-
Show[%,%%]
displays the last two graphs on the same set of axes (note "%3" refers
to the 3rd output. % and %% refer to the last output and the
output before that).
-
ParametricPlot[{Sin[2t],Sin[3t]},{t,0,2Pi}]
produces a parametric graph.
Perform standard Calculus tasks:
-
Limit[Sin[x]/x, x->0] produces
1,
the limit of the specified function as x approaches 0.
-
Limit[E^x/x, x-> -Infinity]
produces 0, the limit of this function
as x grows large.
-
D[x^2,x] produces 2
x, the derivative of x2.
-
D[x^4,{x,3}] produces 24
x, the third derivative of x4.
-
Integrate[Sin[.5x],x] produces
-
0.2 Cos [0.5 x], the antiderivative of the given function.
-
Integrate[6x^2,{x,0,1}]
produces 2, the value of the definite
integral.
-
Integrate[E^x,{x,0,Infinity}]
produces 1, the value of the improper
integral.
-
Integrate[Cos[x]Cos[y],{x,-Pi/2,Pi/2},{y,-Pi/2,Pi/2}]
produces 4, the value of the double
integral. Note that the order is somewhat unusual: the command given
here evaluates in the order that would typically be written "dy dx".
-
Sum[i,{i,1,100}] produces
5050,
the sum of the integers from 1 to 100.
-
N[Sum[(1/2)^i,{i,1,Infinity}]
produces 1.
Produce several varieties of three dimensional
graphs:
-
Plot3D[Sin[x]
Sin[y], {x,-6,6}, {y,-6,6}] produces a graph for the specified
domain.
-
ContourPlot[(Sin[x])^2+1/4*y^2,
{x,0,7Pi/2}, {y,-2,2}] produces a contour map (darker is
lower).
-
DensityPlot[E^(-x^2-y^2),{x,-2,2},{y,-2,2}]
produces a density plot (darker is higher).
-
ParametricPlot3D[{Sin[t],Cos[t],t/Pi},{t,0,2Pi}]
produces a parametric curve plot given the three coordinate functions.
-
ParametricPlot3D[{5Sin[u]
Cos[v], 5Sin[u] Sin[v], 5Cos[u]}, {u,0,Pi}, {v,0,2Pi}] produces
a parametric surface plot given the three coordinate functions.
More advanced options for three dimensional graphs:
(These options can be included just within the final bracket of the Plot3D
or other command)
-
Axes->None eliminates the
axes from the plot.
-
AxesLabel->{"x","y","z"}
labels the three axes with the names given.
-
BoxRatios->{1,1,1} changes
the ratios of length, width, and height from the squished default.
-
Framed->False eliminates
the box normally plotted around the graph.
-
Mesh->False eliminates the
trace lines Mathematica normally includes on the surface.
-
PlotPoints->30 samples 30
points along each axis, rather than the default of 15. This can produce
a much smoother graph.
-
PlotRange->{-.3,.3} specifies
the vertical range to be plotted.
-
Shading->False produces
a graph without any shading of the surface.
-
Ticks->{Automatic,None,{0,Pi/2,Pi,3Pi/2,2Pi}}
puts the tick marks on the x axis in the default locations, puts no tick
marks on the y axis, and forces the tick marks on the z axis to take the
specified locations.
-
ViewPoint->{2,2,2} specifies
the point from which to view the surface.
Generate basic geometric objects:
(use these commands to produce objects, then Show them with each
other or with a Plot3D output)
-
Graphics3D[Point[{Pi/3,0,1/2}]]
creates a point at the coordinates given.
-
Graphics3D[Line[{{-2,-3,0},{5,1,2}}]]
creates a line segment connecting the two points given.
Generate graphical representations of vector fields:
-
If you first load an optional package with the command <<Graphics`PlotField`,
then the command PlotVectorField[{-y,x},{x,-3,3},{y,-3,3}]
plots the vector field F(x,y)
= -yi + xj
for the specified domain.
-
If you first load an optional package with the command <<Graphics`PlotField3D`,
then the command PlotVectorField3D[{y,
-x, 0}/z, {x, -1, 1}, {y, -1, 1}, {z, 1, 3}] produces a plot
of the three dimensional vector field given for the specified domain.