Prof. R. S. Sorbello Dept of Physics, UWM Last update: June 9, 2009
INDEX OF TOPICS Animations, Assumptions, Caution on integrals, Complex variables, Conditionals, Derivatives, Displaying output, Do Loop, Errors, Evaluating expressions, Exporting/Importing data and graphics, Field plots, Functions, Graphics, Graphics incompatibility, Help, Integrals, Keyboard shortcuts and aliases, Lists, Lists and arrays, Matrices, Modules, Page-breaks, Plots, Plot options, Printout, Programming, Series expansions, Simplify, Solving equations, Special constants, Sums, Tabulate function, TeX, Vector analysis, Wolfram databases.
FUNCTIONS Examples of built-in Mathematica functions: Sin[x], Cos[x], Tan[x], Exp[x], Log[x], Sinh[x], Cosh[x], Tanh[x], ArcSin[x], ArcCos[x], ArcTan[x], Abs[x], Sign[x], LegendreP[n, x], BesselJ[n, x], BesselY[n, x], SphericalHarmonicY[l, m, theta, phi].
Defining a function: The preferred way to define a function F[x] is with the set-delayed symbol ":=" as for example, F[x_]:= Tan[x]/x. This construction creates functions that act like Mathematica's built-in functions, i.e., you can call F[x] repeatedly with different numerical or symbolic values of x, and F[x] is evaluated afresh each time. Note the required underscore after the argument x on the left-hand side of the definition (but not on the right hand side).
You can also define a function using an equal sign "=", for example, F[x_]= Tan[x]/x, in which case F[x] is immediately set to the expression on the right-hand side of the equal sign and all symbolic variables take on the specific values they have at the time of the definition. Thus, for the "=" construction, the variable x must not have been assigned a specific value at the time of the definition; otherwise, subsequent evaluation of F[x] will always return F[x] for that original value of x. As a precaution, one should enter the Clear[x] command immediately before using the "F[x_]= " construction. Similarly, if a parameter is present in the function, as for example, F[x_]= k*Tan[x]/x, the parameter k on the right hand side is set to its value at the time of the definition and retains that value in all subsequent evaluations of F[x]. If different values of k are to be used in later calculations, one should enter the Clear[x, k] command immediately before defining F[x_]= k*Tan[x]/x. (This precaution is not needed for the ":=" construction because in that case F[x] is not evaluated until the function is needed.)
For both the ":=" and "=" constructions, entering F[x] after defining the function will retrieve the original function provided that x was not assigned a specific value in a command such as x=c that was entered after the function definition was entered. If a specific value of x was assigned after the definition, then entering "Clear[x];F[x]" or equivalently, entering Clear[x] and then entering F[x] will return F[x] as it was originally defined. Note that if F[x] depends on a set of parameters k1, k2, ... that will be changing over the course of a session and you want to evaluate F[x] using values of the parameters that will be in effect at the time of an evaluation, you can define F[x] by either "F[x_]:= " or by "Clear[x, k1, k2, ...];F[x_]= ". You can also make the parameters explicit variables of the function by replacing F[x_] by F[x_, k1_, k2_, ...].
Defining an expression that may be used as a function: Constructions such as f:=Tan[x]/x and f=Tan[x]/x define an expression in terms of the variable x and can be used instead of the functions F[x] defined earlier. The ":=" and "=" constructions have the same properties for expressions as they do for functions. As in the case of functions defined by the "=" construction, be careful when using the "=" construction that the variable x does not have a specific value at the time of the definition. You can ensure this by entering Clear[x] immediately before using the "=" construction. Similarly, if the expression depends on a parameter k, and the "=" construction is used, be sure to enter Clear[x, k] before entering the definition if you want to vary the values of k over the course of a session. Note that if you define f:=Tan[x]/x, or if you enter Clear[x] followed by the definition f=Tan[x]/x, then in either case if you later enter x=b;f you get Tan[b]/b, then afterwards, if you enter x=c;f you get Tan[c]/c, and if you later enter Clear[x];f you get back Tan[x]/x. To evaluate f for a specific value of x, say x=b, without affecting f, enter f/.x->b (See also section on Evaluating expressions.) The same construction allows you to change the variables of an expression, for example, g=f/.x->y is the same as g=Tan[y]/y. (To get this result with the function F[x], simply enter g=F[y].)
Caution on evaluating or plotting expressions or functions containing derivatives or integrals: In this case, the usual commands for evaluating or plotting expressions may need to be modified by using the Evaluate command to force an immediate evaluation of the derivative or integral. For example, if you try to evaluate the derivative of Sin[x] at x=2 by entering x=2 followed by D[Sin[x], x], Mathematica tries to evaluate D[Sin[2], 2], and generates the error message "2 is not a valid variable." To correct this, enter Evaluate[D[Sin[x], x]] in place of D[Sin[x], x]. If an expression is defined with the ":=" construction, such as f:=D[Sin[x], x], and you want to evaluate f at x=2, enter x=2 followed by Evaluate[f] or enter f/.x->2. Also in any Plot or Table command, use Evaluate[f] in place of f. On the other hand, if you use the "=" construction f= D[Sin[x], x], Mathematica immediately evaluates the derivative and there is no need to use the Evaluate command. Similar considerations apply for expressions containing an integral, as for example, Integrate[Sin[x], x].
Functions that are defined by the ":=" construction have the same behavior as expressions defined by the ":=" construction, so the usual commands for evaluating or plotting need to be modified to force an immediate evaluation of any derivative or integrals appearing in the definition. For example, if F[x_]:= D[Sin[x], x], and the value at x=2 is desired, enter x=2 followed by Evaluate[F[x]], or enter F[x]/.x->2. Similarly, use Evaluate[F[x]] in place of F[x] in Plot and Table commands, for example, Plot[Evaluate[F[x]], {x, 0, 10}] and Table[Evaluate[F[x]], {x, 0, 10, 0.1}]. The same syntax is required if the function contains an integral, as for example, F[x_]:=Integrate[Sin[x], x].
Piecewise functions: These can be created by the commands "Piecewise" or "Which" (for description of "Which" see section on Conditionals). For example: F[x_]:= Piecewise[{{f1, x < x1}, {f2, x2≥x ≥x1}, {f3, x > x2}}] F[x_]:= Which[x < x1, f1, x2≥x ≥x1, f2, x > x2, f3] both define a function equal to f1, f2, or f3, for x<x1, x2≥x ≥x1, or x>x2, respectively, where f1, f2, and f3 may depend on x and other symbolic variables.
SPECIAL CONSTANTS Pi, E, I, Infinity. Note: Mathematica protects these names; they cannot be used as names for other quantities. In Mathematica notebooks, these can be entered in their stylized forms from the keyboard by using the escape-key constructions esc-p-esc, esc-ee-esc, esc-ii-esc, and esc-inf-esc, respectively.
DERIVATIVES Let f be an expression containing x and constant parameters. ( For example: f = x Sin[b x] ) First derivative of f with respect to x: D[f, x] n-th derivative of f with respect to x: D[f, {x, n}]
Let f be some expression containing x and other variables and constants. ( For example: f = x y + y^2 + x Sin[b x] ) First partial derivative of f with respect to x: D[f, x] n-th partial derivative of f with respect to x: D[f, {x, n}] Mixed first partial-derivative: D[f, x, y] or D[D[f, x], y]
INTEGRALS Indefinite integral: Integrate[f, x] (Here f is an expression depending on x) Definite integral from x=x1 to x=x2: Integrate[f, {x, x1, x2}] (Here x1 and x2 may be symbolic variables) Indefinite double Integral: Integrate[f, x, y] (Here f is an expression depending on x and y) Definite double Integral: Integrate[f, {x, x1, x2}, {y, y1, y2}] Assumptions on parameters in an integral (See also Assumptions section): If we know that a parameter, n, is in a certain domain, say n > 1, add-on the option: "Assumptions -> n > 1". Example: Integrate[1/x^n, {x, 1, Infinity}, Assumptions -> n>1] Example for multiple assumptions: Integrate[1/x^(n+m), {x, 1, Infinity}, Assumptions -> {n>1, m>0}] Numerical Integration (necessary if no analytic solution exists): NIntegrate[f, {x, x1, x2}], where now x1, x2 must be numerical quantities, and similarly for double integrals: NIntegrate[f, {x, x1, x2}, {y, y1, y2}] Principal-value integral (Mathematica 5.2 and later): Integrate[1/x, {x, -1, 2}, PrincipalValue -> True] Caution on definite integrals having symbolic parameters: see Caution section.
SUMS Sum[f, {n, nmin, nmax}] , where for example f = 1/n^2 and nmin = 1 and nmax = Infinity. Sum [f, {n, nmin, nmax, nstep}] , where n goes from "nmin" to "nmax" in steps of "nstep". Double sum: Sum[f, {m, mmin, mmax},{n, nmin, nmax}]
SERIES EXPANSIONS Series[f, {x, x0, n}] gives a power series expansion for f as a function of x about the point x=x0 up to terms of order (x - x0)^n. Series[f, {x, x0, n}, {y, y0, n}] gives a successive power series expansion for f first with respect to x then with respect to y. Series[f, {x, x0, n}, Assumptions-> {a>0, b<0}] gives a power series expansion for f subject to assumptions on the parameters a,b that appear in f. (See also Assumptions section).
Math comment: The power series returned by Mathematica is a Taylor series if f is an analytic function at x=x0. Mathematica's power series also exist for functions that are not analytic at x=x0 if the result can be given as a power series containing a finite number of negative powers, or as a power series times a non-expandable function such as Log[x-x0]. Examples: f=1/Sin[x] with x0=0 generates a series with terms 1/x, x, x^3, ..., which is known as a Laurent series; f=BesselY[0, x] with x0=0 generates a power series and Log[x] times a power series.
PLOTS (See also Plot Options immediately following.) Plot[f, {x, x1, x2}] plots specified f from x=x1 to x=x2. Plot[F[x], {x, x1, x2}] plots user-defined function F[x] from x=x1 to x=x2. Plot[{f, g,...}, {x, x1, x2}] plots f, g,... from x=x1 to x=x2. 2-color plot (blue and red): Plot[{f, g}, {x, x1, x2}, PlotStyle -> {RGBColor[0,0,1], RGBColor[1,0,0]}] 2-color plot (blue and red) alternative in Mathematica 6 (or later) : Plot[{f, g}, {x, x1, x2}, PlotStyle -> {Blue, Red}] 3-color plot (blue, red, green): Plot[{f, g, h}, {x, x1, x2}, PlotStyle -> {RGBColor[0,0,1], RGBColor[1,0,0], RGBColor[0,1,0]}] 3-color plot (blue, red, green) alternative in Mathematica 6 (or later) : Plot[{f, g, h}, {x, x1, x2}, PlotStyle -> {Blue, Red, Green}] Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}] gives a 3-d plot of f(x,y). SphericalPlot3D[r, {theta, theta1, theta2}, {phi, phi1, phi2}] gives 3D polar plot with radius r= r(theta, phi) in spherical coords (in Mathematica 6 or later only). ContourPlot[f, {x, xmin, xmax}, {y, ymin, ymax}, ContourShading -> False] gives contour plot of f(x,y) in xy-plane (equi-value curves). DensityPlot is similar to ContourPlot with ContourShading->True but has only shading and no contour lines. PolarPlot[r, {theta, theta1, theta2}] gives 2-d polar plot of radius r=r(theta) from theta1 to theta2. Plot of f(x,y)= 0 in xy-plane in Mathematica 5 and earlier: << Graphics`ImplicitPlot` ImplicitPlot[f == 0, {x, x1, x2}, {y, y1, y2}] (* f can be an expression or a function f[x,y] *) Plot of f(x,y)= 0 in xy-plane in Mathematica 6 (or later) : ContourPlot[f == 0, {x, x1, x2}, {y, y1, y2}] (* f can be an expression or a function f[x,y] *) Parametric plot of y(x) from defined x[t] and y[t]: ParametricPlot[{x[t], y[t]}, {t, 0, tmax}, AspectRatio -> Automatic] To SHOW PLOT in different domains: myplot=Plot[Sin[x], {x, 0, 10}] Show[myplot, PlotRange->{{x1, x2}, {y1, y2}}] (* For all pts: PlotRange->All *) To SHOW several plots superimposed: Show[{myplot1, myplot2, myplot3}, PlotRange->{{x1, x2}, {y1, y2}}] To create single multicolor plot of a family of functions: Plot[Evaluate[Table[Sin[n x], {n, 1, 3}]], {x, 0, Pi}, PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1]}] Mathematica 6 (or later) alternative: Plot[Evaluate[Table[Sin[n x], {n, 1, 3}]], {x, 0, Pi}, PlotStyle -> {Red, Green, Blue}] To create separate plots of a function as some parameter is varied: Mathematica 5 and earlier: Do[Plot[Sin[n x], {x, 0, Pi}], {n, 1, 4}] Mathematica all versions: Do[Print[Plot[Sin[n x], {x, 0, Pi}]], {n, 1, 4}] For more on Plot command inside a Do loop, see the section Graphics incompatibility. To plot lists: see Lists section.
To annotate plots with text, arrows, shapes, etc., in Mathematica 6 and later: Choose menu item Graphics/Drawing Tools or type control-T.
Comment and warning on plotting functions or expressions defined by the ":=" construction: When plotting a function or expression defined by the delayed constructions "F[x_]:= " or "f:= ", the Plot commands run more efficiently if F[x] is replaced by Evaluate[F[x]] and if f is replaced by Evaluate[f]. The use of Evaluate is required if F[x] or f has been defined in terms of a derivative, e.g., F[x_]:= D[Sin[x], x]. (See Caution in Functions section.)
PLOT OPTIONS Plot[f, {x, x1, x2}, option1, option2, ...]
List of Plot options: To restrict plotted values between f = c1 and f = c2: PlotRange -> {c1,c2} To plot all of values of f in the interval (if Mathematica fails to): PlotRange -> All To increase the number of sampled plot points used to 200: PlotPoints -> 200 For labels on x-axis and y-axis: AxesLabel -> {"x", "f"} For dashed curves: PlotStyle -> Dashed or PlotStyle -> Dashing[{0.02, 0.015}] where numbers refer to fraction of total graphic width for each segment, and segments repeat. For colored curves: PlotStyle -> RGBColor[n1, n2, n3] (Specifies relative RGB components, e.g., red is RGBColor[1, 0, 0].) For specifying colors with opacity: RGBColor[n1, n2, n3, a]. For 2 curves full and dashed : PlotStyle -> {{Thickness[0.004]}, {Thickness[0.002], Dashing[{0.012, 0.015}]} where numbers refer to fraction of total graphic width. For tick marks at x1, x2,... and default ticks on y-axis: Ticks-> {{x1, x2, ...}, Automatic} For tick marks at x1, x2,... and y1, y2,... : Ticks-> {{x1, x2, ...}, {y1, y2, ...}} For tick-mark labels, replace x1 by {x1, "label1"}, etc., in lists of two previous tick-mark examples. For plot label: PlotLabel -> FontForm["My Graph", {"Helvetica-Bold", 12}] For grid-lines on plot: GridLines -> Automatic For border around plot: Frame -> True For no ticks on frame: FrameTicks -> None To set origin: AxesOrigin-> {x0, y0} To set y-scale unit to the same display size as x-scale unit: AspectRatio->Automatic To set aspect ratio (height/width) of plot = R: AspectRatio-> R To set font for all future graphics text: $TextStyle = {FontFamily -> "Times", FontSize -> 12} To eliminate shading in the ContourPlot: ContourShading -> False Plot3D: To change viewpoint to coordinates x1, x2, x3: ViewPoint-> {x1, x2, x3} Plot3D: To change viewpoint in Mathematica 6 (or later) : Click, drag and rotate plot as desired. Plot3D: To remove box-lines containing plot: Boxed-> False Plot3D: To set ratios of sides of box containing plot: BoxRatios -> {a, b, c} gives the ratios for the x,y,z sides. Plot3D example: Plot3D[Sin[x y], {x, -Pi, Pi}, {y, -Pi/2, Pi/2}, AxesLabel -> {"x", "y", "sin(x y)"}, BoxRatios -> {1, .5, .3}] where the BoxRatios in the x and y directions, keep the x and y scale-lengths identical.
Alternate syntax for curves in Mathematica 6 (or later) : For colored curves : PlotStyle -> Blue (or PlotStyle -> Red, Green, Yellow, Orange, Purple, Black). For 2 curves full and dashed: PlotStyle -> {{Black}, {Black, Dashed}} For colored, thick or thin, dashed curve: PlotStyle -> {Blue, Thick, Dashed} or {Blue, Thin, Dashed} For 2 curves of different color: PlotStyle -> {Blue, Red} For 2 curves of different color and dashing: PlotStyle -> {{Blue}, {Red, Dashed}} Customized version: PlotStyle -> {{Thickness[0.004], Blue}, {Thickness[0.002], Dashing[{0.012, 0.015}], Red}}
Finding current options and setting global options for Plot (and other commands): To find current options for Plot command: Options[Plot] To find current specific option, like PlotRange in Plot command: Options[Plot, PlotRange] To change default options for session: SetOptions[Plot, PlotRange->All] To determine if a specific option was implimented: AbsoluteOptions[myplot, PlotRange] To find all commands or options whose name begins with "Plot", use wildcard inquiry: ?Plot* To find all commands or options whose name contains "Axes" anywhere, use wildcard inquiry: ?*Axes*
Additional plot options in Mathematica 6 and later: To exclude displaying plot at specified points use Exclusions as in: Plot[Tan[x], {x, 0, 2 Pi}, Exclusions-> {x= Pi/2, 3Pi/2}] To annotate plots or graphics with text, arrows, shapes, etc., use menu item Graphics/Drawing Tools or type control-T. To add slider-control for displaying effect of varying parameters: Manipulate[Plot[Sin[a x + b], {x, 0, 6}], {a, 1, 4}, {b, 0, 10}] Manipulate[Plot[Sin[a x + b], {x, 0, 6}], {{a, 2, "freq"}, 1,4}, {{b, 0, "phase"}, 0, 10}] where {a, 2, "freq"} means the first slider controls a, has a default value of 2, and has the label "freq".
FIELD PLOTS Mathematica's vector field plots display the field at fixed grid points by drawing an arrow emanating from each grid point. The magnitude of the field at a grid point is proportional to the length of the arrow, and the direction of the field at a grid point is in the direction of the arrow. This is not the conventional field-line plot, where the magnitude of the field is proportional to the density of field lines. In Mathematica 7, StreamPlot gives a streamline plot which is similar to the conventional field-line plot, but with possible discrepancies as described below.
In Mathematica 7 :
VECTOR-FIELD PLOTS To create a vector-field plot of A(x,y) having Cartesian components (Ax, Ay): VectorPlot[{Ax, Ay}, {x, x1, x2}, {y, y1, y2}] To specify number of grid pts and size of arrows use VectorPoints and VectorScale, resp.
Example (magnetic field of a TE10 mode in a square waveguide): VectorPlot[{Cos[2 x] Cos[Pi y], 2 Sin[2 x] Sin[Pi y]}, {x, 0, Pi}, {y, 0, 1}, VectorScale -> 0.035, VectorPoints -> {31, 10}, AspectRatio -> 1/Pi, PlotLabel->"TE10 propagation direction ->"] (* Aspect ratio choice makes magnitude of unit vectors along x and y directions of plot identical, so angles of vectors in plot are physical angles in space *)
To create a 3d vector-field plot of A(x,y,z) having Cartesian components (Ax, Ay, Az): VectorPlot3D[{Ax, Ay, Az}, {x, x1, x2}, {y, y1, y2}, {z, z1, z2}]
Example (electric field in region exterior to a uniformly charged sphere): r = (x^2 + y^2 + z^2)^(1/2); w = Which[r > 0.25, 1, r <= 0.25, 0]; VectorPlot3D[{w*x/r^3, w*y/r^3, w*z/r^3}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorPoints -> {8, 8, 8}, VectorScale -> 0.1]
STREAMLINE PLOTS To create a plot of the streamlines of A(x,y): StreamPlot[{Ax, Ay}, {x, x1, x2}, {y, y1, y2}]
Note: Mathematica's streamline plots, as opposed to the conventional field-line plots, are not required to be continuous where there are no sources and are not required to have a local field-line density proportional to the field magnitude. One can try to obtain a conventional field-line plot by specifying an appropriate list of points through which streamlines pass, as shown in examples 1b, 2b and 3b below. Some experimentation with plot options may be required in the general case.
Example 1a (2d point source at the origin): StreamPlot[{x/(x^2 + y^2), y/(x^2 + y^2)}, {x, -1, 1}, {y, -1, 1}]
Example 1b (2d point source at the origin- corrected for continuity and line density): pts = Table[{0.2 Cos[t], 0.2 Sin[t]}, {t, Pi/30, 2 Pi, Pi/30}]; StreamPlot[{x/(x^2 + y^2), y/(x^2 + y^2)}, {x, -1, 1}, {y, -1, 1}, StreamPoints -> {pts, Automatic, 1}, StreamScale -> Full, Epilog -> {Red, Point[pts]}] where in option arguments {pts, Automatic, 1} gives continuous lines cut-off at length 1, Full gives full lines with single arrow, and Epilogue shows the points in the list "pts" in red.
Example 2a (Dipole arrangement of two 2d point sources): StreamPlot[{x/(x^2 + y^2) - (x + 1)/((x + 1)^2 + (y + 1)^2), y/(x^2 + y^2) - (y + 1)/((x + 1)^2 + (y + 1)^2)}, {x, -2, 1}, {y, -2, 1}]
Example 2b (Dipole arrangement of two 2d point sources- corrected for continuity and line density): pts1 = Table[0.1 {Cos[t], Sin[t]}, {t, Pi/20, 2 Pi, Pi/20}]; pts2 = Table[{-1 + 0.1 Cos[t], -1 + 0.1 Sin[t]}, {t, Pi/20, 2 Pi, Pi/20}]; pts = Flatten[{pts1, pts2}, 1]; StreamPlot[{x/(x^2 + y^2) - (x + 1)/((x + 1)^2 + (y + 1)^2), y/(x^2 + y^2) - (y + 1)/((x + 1)^2 + (y + 1)^2)}, {x, -2, 1}, {y, -2, 1}, StreamPoints -> {pts, Automatic, 5}, Epilog -> {Red, Point[pts]}, StreamScale -> Tiny]
Example 3a (Grounded infinite cylinder in a uniform external electric field): r = (x^2 + y^2)^(1/2); v = x/r^2 - x; ex = -D[v, x]; ey = -D[v, y]; exout = Which[r > 1, ex, r <= 1, 0]; eyout = Which[r > 1, ey, r <= 1, 0]; plot = StreamPlot[{exout, eyout}, {x, -5, 5}, {y, -5, 5}]; Show[{plot, Graphics[Circle[{0, 0}, 1]]}]
Example 3b (Grounded infinite cylinder in a uniform external electric field- corrected for continuity and line density): pts1 = Table[{-5, y}, {y, -5, 5, 0.25}]; pts2 = Table[{5, y}, {y, -5, 5, 0.25}]; pts = Flatten[{pts1, pts2}, 1]; r = (x^2 + y^2)^(1/2); v = x/r^2 - x; ex = -D[v, x]; ey = -D[v, y]; exout = Which[r > 1, ex, r <= 1, 0]; eyout = Which[r > 1, ey, r <= 1, 0]; plot = StreamPlot[{exout, eyout}, {x, -5, 5}, {y, -5, 5}, StreamPoints -> {pts, Automatic, 10}, Epilog -> {Red, Point[pts]}, StreamScale -> Tiny]; Show[{plot, Graphics[Circle[{0, 0}, 1]]}]
Note: In examples 1b, 2b and 3b, we specified a set of points for streamlines to pass through where we knew the field field lines are uniformly spaced (exactly in 1b, and to an excellent approximation in 2b and 3b). The uniform spacing is due to symmetry in 1b, due to our choice of points very close to the point sources in 2b, and due to our choice of points far away from the cylinder in 3b. (The manipulation of lists of points using Flatten is described in the section on Lists.)
In Mathematica 6 : To create a vector-field plot of the vector-field A(x,y) having Cartesian components (Ax, Ay): Load the plot package using <<VectorFieldPlots`; VectorFieldPlot[{Ax, Ay}, {x, x1, x2}, {y, y1, y2}]
In Mathematica 5.2 and earlier: To create a vector-field plot of grad f(x,y) from x1 to x2 and y1 to y2: Load the plot package using <<Graphics`PlotField`; then enter: PlotGradientField[f, {x, x1, x2}, {y, y1, y2}] or enter: PlotGradientField[f, {x, x1, x2}, {y, y1, y2}, HeadWidth->0.01, HeadLength->0.01, HeadCenter->0]
SIMPLIFY To simplify algebraic expression for f: Simplify[f] To really simplify, try: FullSimplify[f]. To simplify, making assumptions on domain of variables in expression, see Assumptions section. To test if expr1 is identical to expr2: FullSimplify[expr1-expr2]
Other useful manipulations: Collect[expr, x] (* Collects terms of the same power of x in expr. *) TrigReduce[expr] (* Rewrites products and powers of trig functions in terms of trig functions of combined arguments. *) TrigToExp[expr] (* Converts all trig functions to complex exponentials in expr. *) TrigExpand[expr] (* expands out trig functions in expr. *)
ASSUMPTIONS To make assumptions on variables in expressions used in commands Simplify, FullSimplify, Integrate, Series, Refine:
Simplify[expr, Assumptions-> ...], where ... = a>0, or 1>a>0, or Im[a]==0, or Element[p, Integers], or Element[x, Reals], or Element[{x,y}, Reals], etc. For multiple assumptions, enclose by braces: Simplify[expr, Assumptions->{...}], where {...} = {a>0, b>0, c>0}, etc. Can also use logical-and construction without braces: Simplify[expr, Assumptions->...], where ... = a>0 && b>0 && c>0, etc.
For keyboard entry of Element symbol, use escape-key construction esc-el-esc. Example: For Element[x, Reals], type x esc-el-esc Reals
Note: In Mathematica 6 and later, for the special cases of Simplify, FullSimplify and Refine, can drop "Assumptions-> " and just write the assumption, as in Simplify[f, a>0] or Simplify[f, a>0 && b>0].
Refine[expr, assum] gives the form of expr that would be obtained if symbols in it were replaced by explicit numerical expressions satisfying the assumptions "assum". Example: Refine[Log[x], x<0] gives I*Pi + Log[-x]
EVALUATING EXPRESSIONS To evaluate an expression f numerically: N[f] To evaluate f to an accuracy of M decimal-places: N[f, M]
To evaluate f where f depends on x (and other variables) for a particular value x=a, use u = f /. x -> a This makes u equal to f evaluated at x = a, but leaves f as before. If use x = a, followed by u = f, then need Clear[x] to restore f, as described below. To perform several replacements for variables in f: u = f /. {x -> a, y -> b, z -> c} Alternatively, if define function f[x_, y_, z_] := ..., then u = f[a, b, c] leaves original f[x, y, z] intact.
To clear functions and variables: Clear assigned value for variable x: Clear[x] or x =. Clear assigned values for variables x, a,... : Clear[x, a,...] Clear definition for f or f[x] and assigned values for x, a,... : Clear[f, x, a,...] Ex1: Clear[f, x]; f= x; x= 3; f (* Result is f=3 *) Ex2: Clear[f, x]; f= x; x= 3; x=1; f (* Result is f=1 *) Ex3: Clear[f, x]; f= x; x= 3; x=1; Clear[x]; f (* Result is f=x *).
For distinctions between expressions or functions that are defined by the ":= " and "="constructions, and for possible pitfalls when trying to evaluate them, see the section on Functions.
For correcting errors in evaluating, plotting or tabulating expressions involving derivatives and integrals, see Caution on evaluating or plotting in Functions section.
Limit of an expression: To find limit of f as x->x0: Limit[f, x->x0] To find limit of f as x->x0 from left: Limit[f, x->x0, Direction -> +1]] To find limit of f as x->x0 from right: Limit[f, x->x0, Direction -> -1]]
COMPLEX VARIABLES Mathematica considers symbolic variables to be complex unless specific real values are assigned to them. ComplexExpand[expr] displays real and imaginary parts of expr assuming all variables (if any) are real. Example: ComplexExpand[E^(I x)] gives Cos[x] + I Sin[x] ComplexExpand[expr, {x1, x2,...}] displays expr assuming all variables are real except x1, x2,... which are complex. Example: ComplexExpand[E^(I x), x] gives E^(-Im[x]) Cos[Re[x]]+ I E^(-Im[x]) Sin[Re[x]] To declare variables to be real: This should be done with commands using the Assumptions option. Useful commands: Re[z], Im[z], Abs[z], Conjugate[z], Arg[z], Residue[f,{z, z0}]
DISPLAYING OUTPUT If output from a certain command "expr" is not wanted, follow with ";" as in expr; To show a one-line outline form of the output: expr //Short To show an n-line outline form of the output: Short[expr, n] For displaying numerical output, see Printout section.
TABULATE A FUNCTION To create a table of x and F[x] or a table of x and f from x1 to x2 in increments of xstep: Table[{x, F[x]},{x, x1, x2, xstep}] Table[{x, f},{x, x1, x2, xstep}] The Table command creates a "list". (See Lists section) To display a Table (or list) in columns: Table[{x, f},{x, x1, x2, xstep}]//TableForm To improve visual display of output see Printout section.
Comment/Warning on tabulating functions or expressions defined by the ":=" construction: When tabulating a function or expression defined by the delayed constructions "F[x_]:= " or "f:= ", the Table command runs more efficiently if F[x] is replaced by Evaluate[F[x]] and if f is replaced by Evaluate[f]. In certain cases the use of Evaluate is absolutely required, as is the case when F[x] has been defined in terms of a derivative, e.g., F[x_]:= D[Sin[x], x]. (See Comment in Functions section.)
SOLVING EQUATIONS Algebraic eqs.: Solve[eq, x] (* Here eq has form f(x)==0 *) Solve[{eq1, eq2}, {x, y}] (* Here eq1 and eq2 have form f(x,y)==0. *) To evaluate an expression using solutions: expr /. sol (* For example, sol= Solve[{eq1, eq2}, {x, y}] *) To obtain numerical solutions: Use NSolve instead of Solve. To eliminate variables between a set of equations: Eliminate[{eq1, eq2}, var] or Eliminate[{eq1, eq2, eq3}, {var1, var2}] To test whether two expressions are identical: f==g or FullSimplify[f-g] (*These return True or 0, respectively, if f and g are identical*) To reduce an expression using equations or inequalities for variables: Reduce[expr, vars] or Reduce[expr, vars, dom] if variables defined over domain dom= Reals, Integers, etc.
Transcendental eqs (without symbolic parameters, e.g., solve f=0, where f= Tan[x]-x): Numerical soln: FindRoot[f==0, {x, x0}] (* Searches for a numerical solution to f(x)=0, starting from point x=x0 *) Graphical soln: Plot[f, {x, x1, x2}] (* Observe crossings of x-axis, use smaller x1, x2 range, and repeat. *) Finding local minimum of function f(x) starting hunt at x0: FindMinimum[f,{x,x0}] Finding local minimum of function f(x,y) starting hunt at x0, y0: FindMinimum[f,{{x,x0]},{y,y0}}] Finding local maximum: use FindMaximum in place of FindMinimum.
Differential eqs: DSolve[{eq1, eq2,...}, y[x], x] (* for analytical solutions *) NDSolve[{eq1, eq2,...}, y[x], {x, xmin, xmax}] (* for numerical solutions *) Example: sol = NDSolve[{y''[x]+y[x]==0, y[0]==1., y'[0]==0}, y[x], {x, 0, Pi}] This command gives sol= {{y[x] -> InterpolatingFunction}}. Let f be the y[x] solution as given by this interpolating function. Then f= sol[[1,1,2]], which follows from list extraction rules given below. To plot y[x], use Plot[f, {x, 0, Pi}]. Alternatively, take the solution to be y[x]/.sol, which returns {f}. Since f and {f} give the same Plot and TableForm output, it may be unnecessary to distinguish between them. (If necessary, brackets can be removed by methods in Lists section.)
Extraction rules for output lists of solutions (see also Lists section): Ex 1: sol= {{x -> a, y -> b}, {x -> c, y -> d}}. Here a= sol[[1,1,2]], b= sol[[1,2,2]], c=sol[[2,1,2]], d=sol[[2,2,2]]. Ex 2: sol= {{x -> g}}. Here g= sol[[1,1,2]].
PRINTOUT Given a table or list: zlist=Table[{x, Sin[x], Cos[x]},{x, 0, Pi, 0.1}] To get printout in table form: zlist//TableForm To get printout with larger separation between columns: Table[{x, " ", Sin[x], " ", Cos[x]},{x, 0, Pi, 0.1}]//TableForm To get printout via print statements as values are created: Do[Print[x, " ", Sin[x], " ", Cos[x]], {x, 0, Pi, 0.1}]; To get pretty printout without jags in column alignment: PaddedForm[expr, {nt,nr}] gives nt total digit spaces with nr digits to right of decimal point: pf[w_]:=PaddedForm[w, {10,6}]; Do[ Print[pf[x], pf[Sin[x]], pf[Cos[x]]], {x, 0, Pi, 0.1}]
DO LOOP Do[expr, {i, imin, imax}] (* Index i from imin to imax in steps= 1. For non-integers, i ends at largest value ≤ imax. *) Do[expr, {i, imin, imax, istep}] (* Index i from imin to imax in steps= istep. For non-integers, i ends at largest value ≤ imax. *) Do[expr1; expr2; expr3, {i, imin, imax, istep}] (* Caution: In this form, the final expr is followed by "," not by ";" *) Alternate forms of the previous command: Do[{expr1, expr2, expr3}, {i, imin, imax, istep}] Do[{expr1; expr2; expr3}, {i, imin, imax, istep}] Do[{expr1; expr2; expr3}, {i, imin, imax}, {j, jmin, jmax}] Caution: In above double iteration, the loop over j is done for each i, then i is summed-over last. Using Do-loop to create separate plots of a function as some parameter is varied: Mathematica 5.2 and earlier: Do[Plot[Sin[n x], {x, 0, Pi}], {n, 1, 4}] Mathematica all versions: Do[Print[Plot[Sin[n x], {x, 0, Pi}]], {n, 1, 4}] For discussion of the correct syntax when a Plot command is inside a Do loop, see the section Graphics incompatibility.
CONDITIONALS If[z>a, x=x1] (* If z>a then x=x1, otherwise do nothing. *) If[z>a, x=x1, x=x2] (* If z>a then x=x1, else x=x2 *) If[z == 0 , x=x1, x=x2] (* If z=0 then x=x1, else x=x2 *) If[z>a && z<b , x=x1, x=x2] (* If z>a AND z<b, x=x1, else x=x2 *) If[z>a || z<b , x=x1, x=x2] (* If z>a OR z<b, x=x1, else x=x2 *) Which[test1, value1, test2, value2...] (* Returns value corresponding to first true test *) Example: F[x_]:=Which[x<x1, f1, x ≥x1 && x≤x2, f2, x>x2, f3] creates a piecewise function that is equal to f1, f2, or f3, for x<x1, x2≥x ≥x1, or x>x2, respectively.
GRAPHICS: For making plots of functions and lists see the sections on Plots and Lists, respectively. To annotate graphics with text, arrows, shapes, etc., in Mathematica 6 and later: Choose menu item Graphics/Drawing Tools or type control-T.
Graphics containing points, lines, and geometric figures, etc., can be created and displayed as follows: Without options: Show[Graphics[p]] (In Mathematica 6 or later, can also use Graphics[p] ) With options: Show[Graphics[p], options] Multiple objects: Show[Graphics[{p1, p2, ...}, options] or Show[{Graphics[p1], Graphics[p2], ...}, options] where p is a graphics primitive such as Point, Line, Circle, etc, with appropriate arguments, and the options are those available for plots and described in the section on Plot Options. In Mathematica 6 (or later), braces surrounding the argument of the Show command can be omitted, as in Show[Graphics[p1], Graphics[p2], ..., options]. For other differences in graphics commands between Mathematica 5 and later versions, see the section on Graphics incompatibility
Useful primitives: Point[{x,y}], Line[{{x1,y1}, {x2,y2},...}], Circle[{x,y}, r], Disk[{x,y}, r], Rectangle[{xmin, ymin}, {xmax, ymax}], Text[expr, {x,y}]. The argument of Line is a list of at least two points, and in Mathematica 6 (or later) , the argument of Point may be a list of points, as in the Line primitive, in which case all those points will appear in the graphic. The {x,y} coordinates specify the center of Circle, Disk or Text, and r is the radius of Circle or Disk.
Options: Options associated with the display of the entire set of primitives are placed at the end of the Show command. An option associated with a single primitive is known as a "graphics directive" and is combined with the primitive inside braces as in the following examples: {PointSize[d], Point[{x,y}]}, {Thickness[d], Line[{{x1,y1}, {x2,y2}}]}, {Thickness[d], RGBColor[1,0,0], Circle[{x,y}, r]}, where d is the fraction of the total width of the graphic. (In Mathematica 6 (or later) , RGBColor[1,0,0] can be replaced by Red.)
Combining plots and graphics primitives in Mathematica 6 (or later) : Show[myplot, Graphics[p], options], where for example myplot= Plot[Cos[x], {x, 0, 10}, AspectRatio -> Automatic] Show[myplot, Graphics[{{p1, option1}, {p2, option2}, {p3, option3}}], options] where option1, option2, option3 are options ("graphics directives") associated with primitives p1, p2, p3, resp.
Combining plots and graphics primitives in Mathematica 5: Express the plot data in a list (or Table) form and plot it as a Graphic using Line primitive: Show[Graphics[{Line[T], p2, p3}, options] Show[Graphics[{{Line[T]], optionT}, {p2, option2}, {p3, option3}}, options}], where for example, T= Table[{x, Exp[-0.2x]Sin[2x]}, {x, 0, 10, .1}] and optionT is RGBColor[1,0,0].
Examples in Mathematica 6 (or later) : T = Table[{x, Exp[-0.2x]Sin[2x]}, {x, 0, 10, .1}]; (* Creates list for later examples *) myplot = Plot[Exp[-0.2 x] Sin[2 x], {x, 0, 10}, AspectRatio -> Automatic] (* Creates plot for next example *) Show[myplot, Graphics[{Point[{0, 0}], Circle[{0, 0}, 1]}], PlotRange -> {{-2, 10}, {-2, 2}}] Show[Graphics[{Point[{0, 0}], Line[T], Circle[{0, 0}, 1] } ]] Show[Graphics[{{PointSize[.05], Point[{0, 0}]}, {Blue, Line[T]}, {Thickness[0.005], Red, Circle[{0, 0}, 1]}}], PlotRange -> {{-2, 10}, {-2, 2}}, Axes -> True] Note that Show[Graphics[Line[T]]] gives the same result as ListPlot[T, PlotJoined->True], which appears in the section on Lists.
Examples in Mathematica 5: To get correct aspect ratio and plot range, need to include options for AspectRatio and PlotRange in Show command. (Also, color option must be RGBColor.) : Show[Graphics[{Point[{0,0}], Line[T], Circle[{0,0}, 1]}], AspectRatio -> Automatic, PlotRange -> {{-1, 10}, {-1, 1}}] Show[Graphics[{{RGBColor[0,0,1], Line[T]}, {PointSize[.05], Point[{0,0}]}, {Thickness[0.005], RGBColor[1,0,0], Circle[{0,0}, 1]}}], AspectRatio -> Automatic, PlotRange -> {{-2, 10}, {-2, 2}}]
LISTS Specifying elements in a list: A list is a collection of items contained within curly-brackets, such as {a, b, c}. Other examples: u= {{a, b}, {c, d}, {e, f}}; v= {{j, k, p}, {q, r, s}}; x= {{c1}, {c2}, {c3}}; w= {t}; To pick-out elements of lists, u[[n]], v[[n]], x[[n]], w[[n]] refer to n-th element of lists, and u[[n,m]], v[[n,m]], x[[n,m]] refer to n-th element, m-th sub-element: u[[1]]= {a, b}; u[[1,2]]= b; u[[3,1]]=e; v[[1]]= {j, k, p}; v[[1,2]]= k; v[[2,1]]=q; x[[1,1]]=c1; x[[2,1]]=c2; w[[1]]=t; To remove all internal brackets from a list: unew= Flatten[u] (* Result is unew= {a, b, c, d, e, f} *) To remove external brackets from a one-number list: wnew=w[[1]] or {wnew}= w (* Result is wnew= t *) To string-together lists: If y= {{a, b}, {c, d}}, and z= {{e, f}, {g, h}}, then: Flatten[{y, z}, 1] gives {{a, b} , {c, d}, {e, f}, {g, h}} which is said to flatten the list {y, z} to level 1. Similarly, Flatten[{y, z}, 2] gives {a, b, c, d, e, f, g, h} which flattens to level 2.
To create a list: data=Table[{x, Sin[x]}, {x, 0, 10, .2}] (* Creates data= {{0, Sin[0]},{.2, Sin[.2]}, ... , {10, Sin[10]}}. *) To display a list in neat table form: data//TableForm
To combine two 1-d lists to create a paired list: xdata=Table[x, {x, 0, 10, .2}] (* Creates xdata= {0, .2,...,10}. *) ydata=Table[Sin[x], {x, 0, 10, .2}] (* Creates ydata= {Sin[0], Sin[.2],...,Sin[10]}. *) data=Transpose[{xdata,ydata}] (* Creates data= {{x1, y1},{x2, y2}, ...} as before *) Alternate method: data=Table[{xdata[[i]], ydata[[i]]},{i, 1, imax}] (* Here must supply imax = dimension of array = (10/0.2)+1 = 51. *)
To plot a list or multiple lists: ListPlot[data] (* This puts data points on plot, where data is a paired list as previously defined *) ListPlot[data, PlotJoined->True] (* To connect data points on plot *) ListPlot[{data1, data2}] (* This replaces obsolete "MultipleListPlot" command*)
To obtain an interpolating function for f[x] from lists for f and x : flist=Table[Sin[x], {x, 0, 2Pi, 0.05}]; xlist=Table[x, {x, 0, 2Pi, 0.05}]; f=ListInterpolation[flist, {xlist}]; Plot[f[x],{x ,0 , Pi}] Note the function is called as f[x] although it was created from "f=ListInterpolation..." without x-variable written. The x-variable in f[x] is associated with {xlist}. (Note: This method provides another way to make a smooth plot of a list.)
List Extraction-Rules (for output lists created by commands such as Solve): When the list contains an arrow "->" between items, it acts like a "," element-separator:
Ex. 1: sol= {{x -> a, y -> b}, {x -> c, y -> d}}. Then a= sol[[1,1,2]], b= sol[[1,2,2]], c=sol[[2,1,2]], d=sol[[2,2,2]].
Ex. 2: sol= {{x[t] -> Cos[t]}}. Then Cos[t]=sol[[1,1,2]]. Here the first (and only) element within the external brackets is {x[t] -> Cos[t]}, and inside this first element, the first (and only) sub-element inside its surrounding brackets is x[t] -> Cos[t], which contains two sub-sub elements separated by "->".
Ex. 3: sol= {{x -> a}, {x -> b}, {x -> c}, {x -> d}}. Then a=sol[[1,1,2]], b=sol[[2,1,2]], c=sol[[3,1,2]], d=sol[[4,1,2]]
Ex. 4: sol=Solve[{eq1==0, eq2==0, eq3==0, eq4==0},{w,x,y,z}]. The solution for these 4 simultaneous eqs in 4 unknowns w,x,y,z is returned in the form {{w -> a}, {x -> b}, {y -> c}, {z -> d}}, so the solution for x is sol[[2,1,2]].
LISTS AND ARRAYS In the following, farray and xarray are 1-d arrays, meaning that farray[i] and xarray[i] are each a number (or an expression) that depends on i for each i in range i=1 to imax. The representations of farray and xarray as lists are flist and xlist, respectively.
To make a 1d-list from a 1d-array: flist=Table[farray[i], {i, 1, imax}] To make a 1d-array from a 1d-list: Do[farray[i]=flist[[i]], {i, 1, imax}]; To make a paired-list from two 1-d arrays: xflist=Table[{xarray[i], farray[i]}, {i, 1, imax}] To make a paired-list from two 1-d lists: xflist=Table[{xlist[[i]], flist[[i]]}, {i, 1, imax}] To plot a list of paired elements: ListPlot[xflist, PlotJoined->True] To make 2 arrays from a 2d-list: Do[{xarray[i]=xflist[[i,1]]; farray[i]=xfist[[i,2]], {i,1,imax}] To make an array from a function: Do[ x=x1+(i-1)*(x2-x1)/(imax-1); farray[i]=f[x], {i, 1, imax}]
To make an array from a list whose elements are enclosed in brackets: If U = {{U1}, {U2}, {U3}, ...}, then to make a 1-d array whose i-th entry is Ui: Do[Uarray[i]= U[[i,1]], {i, 1, imax}].
To create a 2-d array Marray[i,j] from a function M[H,T]: Specify M[H,T], the ranges Hbeg, Hend, Tbeg, Tend, and the number of i,j points = imax, jmax, resp. Example: M[H_,T_]:=Tanh[H/T]; Hbeg = -4; Hend = 4; Tbeg = 1; Tend = 3; imax = 100; jmax = 100; Then to create Marray[i,j] enter: dH = (Hend - Hbeg)/(imax - 1); dT = (Tend - Tbeg)/(jmax - 1); Do[H = Hbeg + (i - 1)*dH; T = Tbeg + (j - 1)*dT; Marray[i, j] = M[H,T], {i, 1, imax}, {j, 1, jmax}]
To create and plot a function M[H,T] from a 2-d array Marray[i,j] having structure as above: M[H_, T_] := Marray[ IntegerPart[1 + (H - Hbeg)/dH], IntegerPart[1 + (T - Tbeg)/dT] ]; Plot3D[M[H, T], {H, Hbeg, Hend}, {T, Tbeg, Tend}]
MATRICES and MATRIX EQUATIONS Enter Matrices and N-dimensional vectors from the input palette using the 2-by-2 small-box array surrounded by parentheses for a matrix, and the vertical array of 2 small boxes surrounded by parentheses for a vector. To add additional rows, press the return key while holding the control key down (control-return). To add additional columns press the comma key while holding the control key down (control-,).
For matrix multiplication use a period. For example, M1.M2 where M1 and M2 are matrices. Useful commands: Inverse[M], Det[M], Tr[M], Transpose[M], ConjugateTranspose[M], MatrixPower[M, n], Eigensystem[M], Eigenvalues[M]
To display matrix M as columns and rows, use M//MatrixForm or M//TraditionalForm. Otherwise, Mathematica will display matrix as a list of lists. To display vector X as a column, use X//MatrixForm or X//TraditionalForm. To display matrices and vectors as columns and rows throughout session, choose Cell/Default Output Type/TraditionalForm.
To use matrices to solve a set of linear, inhomogeneous eqs: Express eqs as Y=M.X, where Y is a known N-dimensional vector and M is a known N-by-N matrix. Solve for unknown N-dimensional vector X, using the command X=Inverse[M].Y
ANIMATIONS (In Mathematica 6 or later) In Mathematica 6 or later, the built-in command Animate[expr, {t, t1, t2}] displays animations in a nice interface without having to load an animation package and without the cumbersome steps of previous versions, where the entire sequence of still-frames were displayed and you had to select and animate them. If the animation is jittery, the number of still-frames, nf, can be increased using Animate[expr, {t, t1, t2, dt}], where dt=(t2-t1)/(nf -1) is the time interval between successive frames. For Mathematica versions before 6.0, see the section Animations in Mathematica 5.2 or earlier.
Examples: Animate[Plot[Cos[t]Sin[x], {x, 0, 2Pi}, PlotRange -> {-1.1,1.1}], {t, 0, 2Pi}] Animate[Plot3D[Sin[2x]Sin[3y]Cos[t], {x, 0, Pi}, {y, 0, Pi}, PlotRange -> {-1.1, 1.1}], {t, 0, 2Pi}] For a mesh in animated 3-d plots, use following option in Plot3D: Mesh -> 20
Options for Animate: AnimationRepetitions->n, AnimationRunning->False,   DefaultDuration -> m, where n= no. of animation cycles before stopping, m= no. of seconds animation takes to run, and False means that the animation will not run until start button is pressed.
Beware of unexpected behavior: The Animate command will fail if the expression to be plotted is written as the real or imaginary part of a previously defined complex expression, as for example: f=Exp[I(x-t)]; Animate[Plot[Re[f], {x, 0, 2Pi}, PlotRange -> {-1,1}], {t, 0, 2Pi}]. But if Re[f] is explicitly written as Re[Exp[I(x-t)]] in the previous Animate command, the animation works. An elegant alternative is to write a module as follows: mymod[f_] := Module[{}, Animate[Plot[f, {x, 0, 2 Pi}, PlotRange -> {-2, 2}], {t, 0, 2 Pi}]] f = Re[Exp[I(x-t)]]; mymod[f]
To animate a function f[t] as t evolves from t1 to t2 (specify f, t1, t2, and function range fmin, fmax): Animate[Plot[f[tp], {tp, t1, t}, PlotRange -> {{t1, t2}, {fmin, fmax}}], {t, t1+.00001(t2-t1), t2}] where for example we could have previously defined f[t_]:= Sin[t]; t1= 0; t2= 2 Pi; fmin=-1; fmax=1; (* Note: The t1+.00001(t2-t1) start for t avoids the error-message that the plot of f[tp] has a zero range of tp in the first frame when tp=t=t1. *)
To follow the single point evolving as above without a trajectory trail: Animate[Graphics[{PointSize[0.01], Point[{t, f[t]}]}, PlotRange -> {{t1, t2}, {fmin, fmax}}], {t, t1, t2}]
NOTE: The following alternative eliminates the viewing box and slider display of the previous animations and may sometimes give better results: Use the Mathematica 5.2 syntax but with the Plot command surrounded by a Print command, i.e., replace "Animate[Plot[" by "Do[Print[Plot[...],...]". The animation is then activated by collapsing the output graphics cells (by double clicking on the group) and choosing the menu item Graphics/Rendering/Animate Selected Graphics. For example, the command lines to create the graphics cells for the previous animations are: Do[Print[Plot[Cos[t] Sin[x], {x, 0, 2 Pi}, PlotRange -> {-1.1, 1.1}]], {t, 0, 2 Pi}] Do[Print[Plot3D[Sin[2 x] Sin[3 y] Cos[t], {x, 0, Pi}, {y, 0, Pi}, PlotRange -> {-1.1, 1.1}]], {t, 0, 2 Pi}] Do[Print[Plot[f[tp], {tp, t1, t}, PlotRange -> {{t1, t2}, {fmin, fmax}}]], {t, t1+.00001(t2-t1), t2}] Do[Print[Graphics[{PointSize[0.01], Point[{t, f[t]}]}, PlotRange -> {{t1, t2}, {fmin, fmax}}]], {t, t1, t2}] Now the animation is activated by collapsing the graphics cells (by double clicking on the group), selecting them, and choosing the menu item Graphics/Rendering/Animate Selected Graphics.
Trajectory animations: To create a trajectory animation from time t=t1 to t=t2 for a given set of Cartesian coordinate functions x[t] and y[t]: Animate[ParametricPlot[{x[tp], y[tp]}, {tp, t1, t}, AspectRatio -> Automatic, Axes -> False, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {t, t1+.00001(t2-t1), t2}] where must specify numerical values for t1, t2, and the plot ranges xmin,xmax, ymin,ymax. (To include axes, use option Axes->True.) CYCLOID EXAMPLE: x[t_]:= t-Sin[t]; y[t_]:= 1-Cos[t]; t1 = 0; t2 = 20; xmin = 0; xmax = 20; ymin = -.1; ymax =2.1; Animate[ParametricPlot[{x[tp], y[tp]}, {tp, t1, t}, AspectRatio -> Automatic, Axes -> False, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {t, .00001(t2-t1), t2}] To see the previous animation as a moving dot without a trajectory trail: Animate[Graphics[{PointSize[0.01], Point[{x[t], y[t]}]}, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {t, t1, t2}] More elaborate cycloid animation: Animate[Show[ParametricPlot[{x[tp], y[tp]}, {tp,t1,t}], Graphics[{{Red, Circle[{t,1}, 1]}, {PointSize[0.005], Point[{t, 1}]}, {PointSize[0.015], Point[{x[t],y[t]}]}, {Blue, Line[{{x[t],y[t]}, {t,1}}]}, {Thin, Line[{{0,0}, {t2,0}}]}}], Axes -> False, AspectRatio -> Automatic, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {t, t1 + .00001 (t2-t1), t2, dt}]
Trajectory animations using lists: In these examples, we calculate x[t],y[t] trajectory points at a large number of points (npts), for t values equally spaced from t1 to t2, and store the result in lists. As shown below, these list entries are then retrieved and used in the animations. npts = 200; (* npts= number of (x,y) data points= no. of frames *) dt = (t2 - t1)/(npts - 1); mylist = Table[{x[t], y[t]}, {t, t1, t2, dt}]; (* This list is the full set of x[t], y[t] points *) mylist2[n_] := Table[{mylist[[m, 1]], mylist[[m, 2]]}, {m, 1, n}] (* This list is the partial set of x[t], y[t] points up to the n-th step *) Animate[ListPlot[mylist2[n], PlotJoined -> True, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {n, 1, npts}] To see the previous animation as a moving dot without trajectory trail: Animate[ListPlot[{mylist[[n]]}, PlotStyle -> PointSize[0.01], PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {n, 1, npts, 1}] (* Note the explicit step increment of 1 in the iterator not required previously. *) Alternate commands for the previous two animations: Animate[Graphics[Line[mylist2[n]], PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {n, 1, npts}] (* For thicker line, replace Line[mylist2[n]] by {Thickness[0.015], Line[mylist2[n]]} in previous command *) To see the previous animation as a moving dot without trajectory trail: Animate[Graphics[{PointSize[0.01], Point[{mylist[[n]]}]}, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {n, 1, npts, 1}]
Creating GIF Animations: To make a gif animation to insert into Powerpoint or into a webpage or to make a movie of the animation, construct a Table of plots and use Export command as described in the section Exporting/Importing data and graphics. An example of an animated webpage made by this method is shown at www.uwm.edu/~sorbello/classes/cycloid.html.
ANIMATIONS (In Mathematica 5.2 or earlier) Load animation package with <<Graphics`Animation` and create a sequence of plots using the commands listed below. Double-click on the bracket containing all the output graphics cells (but not the input cell) to collapse the output cells to a single pane. Then choose menu item Cell/Animate Selected Graphics.
Note on compatibility with Mathematica 6 (or later) : All the Mathematica 5 animations listed below will work in Mathematica 6 (or later) if the Do command is replaced by the Animate command. (See previous section Animations in Mathematica 6 or later.) However, the modified animations will not work in Mathematica 5. If compatibility is desired, then each graphics command, such as Plot, ListPlot, Graphics, etc., inside a Do loop must be enclosed by a Print command, following the rule given in the Graphics incompatibility section. In such cases, the animation procedures and display for both versions of Mathematica revert to those of Mathematica 5, except that the menu-item for animating cells is Graphics/Rendering/Animate Selected Graphics.
Examples Do[Plot[Cos[t]Sin[x], {x, 0, 2Pi}, PlotRange -> {-1.1, 1.1}], {t, 0, 2Pi}] Do[Plot3D[Sin[2x]Sin[3y]Cos[t], {x, 0, Pi}, {y, 0, Pi}, PlotRange -> {-1.1, 1.1}], {t, 0, 2Pi}] For a mesh in animated 3-d plots, use following option in Plot3D: Mesh -> 20 To animate a function f[t] as t evolves from t1 to t, specify t1, t2, function range fmin, fmax: Do[Plot[{tp, f[tp]}, {tp, t1, t}, Axes -> True, PlotRange -> {{t1, t2}, {fmin, fmax}}], {t, t1+.00001(t2-t1), t2}] (* Note: The t1+.00001(t2-t1) start for t avoids the error-message that the plot of f[tp] has a zero range of tp in the first frame when tp=t=t1. *) To animate a function f[t] as above, but with specified time interval between frames = dt (nominally dt=(t2-t1)/100 for 101 frames): Do[Plot[{tp, f[tp]}, {tp, t1, t}, Axes -> True, PlotRange -> {{t1, t2}, {fmin, fmax}}], {t, t1+.00001(t2-t1), t2, dt}] To follow the single point evolving as above without a trajectory trail: Do[Show[Graphics[{PointSize[0.01], Point[{t, f[t]}]}, PlotRange -> {{t1, t2}, {fmin, fmax}}, Axes -> False]], {t, t1, t2, dt}]
Trajectory animations: To create a trajectory animation from time t=t1 to t=t2 given x[t] and y[t]: Do[ParametricPlot[{x[tp], y[tp]}, {tp, t1, t}, AspectRatio -> Automatic, Axes->False,PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {t, t1+.00001dt, t2, dt}] where must specify numerical values for t1, t2, the plot ranges xmin, xmax, ymin, ymax, and nominally take dt=(t2-t1)/100 for 101 animation frames. CYCLOID EXAMPLE: x[t_]:= t-Sin[t]; y[t_]:= 1-Cos[t]; t1 = 0; t2 = 20; xmin = 0; xmax = 20; ymin = -.1; ymax =2.1; dt = 0.2; Do[ParametricPlot[{x[tp], y[tp]}, {tp, t1, t}, AspectRatio -> Automatic, Axes->False,PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {t, t1+.00001dt, t2, dt}] To see the previous animation as a moving dot without a trajectory trail: Do[Show[Graphics[{PointSize[0.015], Point[{x[t], y[t]}]}, PlotRange -> {{xmin, xmax}, {ymin, ymax}}, Axes -> False]], {t, t1, t2, dt}] More elaborate cycloid animation: Do[Show[Graphics[{Line[Table[{x[tp], y[tp]}, {tp, t1, t, dt}]], {PointSize[0.015], Point[{x[t], y[t]}]}, {RGBColor[1, 0, 0], Circle[{t, 1}, 1]}, {PointSize[0.01], Point[{t, 1}]}}, AspectRatio -> Automatic, PlotRange -> {{xmin, xmax}, {ymin, ymax}}]], {t, t1+.0001(t2 - t1), t2, dt}]
Trajectory animations using lists: In these examples, we calculate x[t],y[t] trajectory points at a large number of points (npts), for t values equally spaced from t1 to t2, and store the result in lists. As shown below, these list entries are then retrieved and used in a do-loop command to create still-frames, which are subsequently animated as previously described. npts = 100; (* npts= number of (x,y) data points= no. of frames *) dt = (t2 - t1)/(npts - 1); mylist = Table[{x[t], y[t]}, {t, t1, t2, dt}]; (* This list is the full set of x[t], y[t] points *) mylist2[n_] := Table[{mylist[[m, 1]], mylist[[m, 2]]}, {m, 1, n}] (* This list is the partial set of x[t], y[t] points up to the n-th step *) Do[ListPlot[mylist2[n], PlotJoined -> True, PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {n, 1, npts}] To see the previous animation as a moving dot without trajectory trail: Do[ListPlot[{mylist[[n]]}, PlotStyle -> PointSize[0.01], PlotRange -> {{xmin, xmax}, {ymin, ymax}}], {n, 1, npts}]
EXPORTING AND IMPORTING DATAFILES AND GRAPHICS Exported files are sent to a default directory (usually user's home directory). To find this directory: Directory[] To change this directory: SetDirectory["pathname"], where, e.g., pathname= /Users/home/mathwork.
DATAFILES To create and Export datafiles (such files must have the ".dat" suffix): Begin with a datalist or Table, e.g., mylist=Table[{x, Sin[x], Cos[x]},{x, 0, 7, 0.1}] Export["myfile.dat", mylist] This creates the datafile myfile.dat which consists of 71 lines, each line having values of x, Sin[x], Cos[x] separated by spaces. To append an expression to an existing file: expr >>>myfile (same as PutAppend[expr, "myfile"]) To make an Excel file from a created datafile: Change the filename suffix ".dat" to ".xls" and open the new file in Excel.
To Import a datafile as a list: zlist= Import["myfile.dat"], where myfile.dat contains lines of data with numbers on each line separated by space(s). To create 1-d arrays from above list: Do[A[i] = zlist[[i,1]]; B[i]=zlist[[i,2]], C[i]=zlist[[i,3]], {i, 1, imax}] where for our previous myfile.dat, A, B, C, refer to x, Sin[x], and Cos[x], respectively, and there are imax=71 entries for each of the arrays A[i], B[i], C[i].
GRAPHICS, ANIMATIONS AND MOVIES To Export a single graphic (for subsequent use by Word, Powerpoint, Web Browsers, etc.): Method 1: Select Graphic, then use menu item File/Save Selection As...GIF (or choose PDF, JPG, or other file type in menu) Method 2: Export["myfile.gif", myplot] to create a gif file from myplot. Similarly, "myfile.jpg" creates jpg file, etc.
To insert the exported graphic file in Word, etc.: Conventional method: Use Word menu item Insert/Picture ...from file (and browse to the saved file) Better method: Create a PDF file of the selection, as in Method 1 above, then open it in Adobe Acrobat, use the "snapshot tool" (camera icon) to capture (and automatically copy) the desired portion of the pdf file. Then paste into Word, and resize as desired. (For a Mac computer, the screen image and printout by this method were better than obtained by the conventional method. The screen image and the hardcopy printout from an HP inkjet printer were excellent, but the printout from an HP laserjet printer was not as sharp.)
To create a gif animation from a Table of plots (or other graphics): Export["myfile.gif", myplots], where myplots is a Table of plots or other graphics and myfile.gif is the created gif animation file to be inserted into Powerpoint as a movie or to be be used as an image source in an html file. Example of a Table of plots: myplots=Table[Plot[Cos[t]Sin[x], {x, 0, 2Pi}, PlotRange-> {-1, 1}], {t, 0, 2Pi}] An example of an animated webpage made by this method is shown at www.uwm.edu/~sorbello/classes/cycloid.html.
To create a movie (in .avi format) from a Table of plots (or other graphics): Export["myfile.avi", myplots], where myplots is a Table of plots or graphics (as in previous paragraph) and myfile.avi is the created movie. (The movie can be opened in QuickTime, for example.)
To create a QuickTime movie (in .mov format) from a sequence of plots (or other graphics): Create the desired sequence, e.g., myplots = Do[Print[Plot[Cos[t] Sin[x], {x, 0, 2 Pi}, PlotRange -> {-1, 1}]], {t, 0, 2 Pi}] then select the set and use menu item File/Save Selection As.../QuickTime.
PROGRAMMING Example of simple numerical integration program: F[x_]:=x^2 mysum=0.0; x1=0.0; x2=10.0; npts=1001; dx= (x2-x1)/(npts-1); Do[ x=x1 + (n-1)*dx; mysum=mysum + F[x], {n,1,npts}]; integralval = mysum*dx; Print["Integral= ", integralval]
Modules (sub-routines): Module[{x, y, ...}, expr1; expr2; exprlast] specifies that occurrences of the symbols x, y, ...in expr1, expr2, etc., should be treated as local. Value of exprlast is value returned by the module. The following is a "module" (subroutine) of the previous program. One can specify x1, x2, and npts in a sub-routine call (assuming F[x] already has been defined). To integrate a pre-existing F[x] function using this module, enter, for example: myintegrate[0,10,1001], where the module myintegrate is defined as follows:
myintegrate[x1_,x2_,npts_]:=Module[{n,mysum,x,dx,integralval}, mysum=0.0; dx= (x2-x1)/(npts-1); Do[{ x=x1 + (n-1)*dx, mysum = mysum + F[x]}, {n,1,npts}]; integralval=mysum*dx ];
VECTOR ANALYSIS Load this package in Mathematica 5 and earlier by typing: <<Calculus`VectorAnalysis` Load this package in Mathematica 6 (or later) by typing: <<VectorAnalysis` Choose spherical coordinate system by typing: SetCoordinates[Spherical[r, theta, phi]] Choose cartesian coordinate system by typing: SetCoordinates[Cartesian[x, y, z]] Choose cylindrical coordinate system by typing: SetCoordinates[Cylindrical[r, phi, z]] Vector operations: Div[f], Curl[f], CrossProduct[v1,v2], v1.v2, where vector fields f, v1, v2 are specified as { , , } and v1.v2 is the dot product. Gradient and Laplacian of a function g: Grad[g], Laplacian[g] Over-riding the set-coordinates: Div[F[x, y, z], Cartesian[x, y, z]] if previously SetCoordinates[Spherical[r, theta, phi]]
If you want programs to run in both versions of Mathematica, this can often be accomplished by minor modification of incompatible graphics commands. In some cases, the incompatibility is caused by Plot commands inside Do loops, and this can be fixed easily by enclosing each Plot command by a Print-command. Similarly, commands such as Graphics[Point...] inside Do loops need to be enclosed by a Print statement. This syntax is needed because Mathematica 6 (or later) treats graphics output like other output and therefore suppresses it in the execution of a Do loop unless a Print-command is used. The same syntax is valid in Mathematica 5.2 and earlier, but there the Print-command was optional.
HELP In addition to Mathematica's "HELP" menu, you can get help on a specific command by typing ?Command. For example: ?Plot. You can also use the "wildcard" character "*", as in ?Plot*, which returns the names of all commands or options whose name begins with "Plot" and provides links to help on each item. Similarly, to find help on all commands or options containing the word "Point" anywhere, use ?*Point*. There is also free on-line help at Wolfram's Documentation Center, which is the same as the "HELP" menu in Mathematica 6 (or later). Shortcut to get help about a specific command or option appearing as a text-string xxxx in Mathematica 6 or later: Select text-string and press F1 key.WOLFRAM DATABASES In Mathematica 6 and later, you can access data from physics, chemistry, mathematics, etc., that are in the database on the Wolfram site. To see the database categories use the help inquiry: ?*Data For example, to see a specific molecular structure that you can dynamically rotate: ChemicalData["Caffeine", "MoleculePlot"] More generally ChemicalData["name","property"] gives the value of the specified property for the chemical "name". ChemicalData["name"] gives a structure diagram for the chemical with the specified name. ChemicalData["class"] gives a list of available chemicals in the specified class.
KEYBOARD SHORTCUTS AND ALIASES Greek symbols: esc-g-esc for gamma, esc-G-esc for capital gamma, etc. Other esc-X-esc shortcuts: X= inf, hb, el, deg, vec, for infinity, h-bar, element, degree, vector-sign, resp. X= int, dd, ii, ee, for integral sign, differential, I, E, resp. (These are stylized, active forms).
Creating custom keyboard shortcuts (aliases): To create a notebook where if you type esc-name1-esc or esc-name2-esc you get text1 and text2, resp.: nb = CreateDocument[{}, InputAliases -> {"name1" -> "text1", "name2" -> "text2"}] Example: nb=CreateDocument[{}, InputAliases -> {"aa" -> "Assumptions->", "tt" -> "//TableForm", "p1" -> "Plot[f, {x, x1, x2}, PlotRange->All]", "p2" -> "Plot[{f, g}, {x, x1, x2}, PlotStyle -> {Blue, Red}]", "p2d" -> "Plot[{f, g}, {x, x1, x2}, PlotStyle -> {{Black}, {Black, Dashed}}]", "p3" -> "Plot[{f, g, h}, {x, x1, x2}, PlotStyle -> {Black, Blue, Red}]", "p3d" -> "Plot[{f, g, h}, {x, x1, x2}, PlotStyle -> {{Black, Thick}, {Black, Thick, Dotted}, {Black, Thick, Dashed}}]" }]
Exponents: x to the power y can be entered as x control-^ y.
Over-symbol: control-& (For x-hat: x control-& ^ control-space. For x-vector: x control-& esc-vec-esc control-space.)
Symbol shortcuts based on TeX language (for Mathematica Notebooks): esc-\TeX-esc, where \TeX denotes the TeX command for a single Greek or mathematical symbol. For example, \TeX= \gamma, \Gamma, \hbar, \infty, \partial, \times, \sum, \int, \propto, \rightarrow, \sim, \equiv, \cdot, \perp, \parallel
TeX Mathematica to TeX conversion: TeXForm[expr] TeX to Mathematica conversion: ToExpression["input",TeXForm], where, for example, input = \sqrt{b^2-4ac}
NOTEBOOK PAGE BREAKS To see them in Mathematica 5 or earlier: Format/Show PageBreaks To see them in Mathematica 6 (or later) : File/Printing Settings/Show Page Breaks To return to notebook view: Use same menu items as above (toggle switch). To create or remove pagebreaks use the page break palette. (To get it, go to www.wolfram.com. and in the Search Site box, type: page break palette.) In Mathematica 6 (or later) , can also create pagebreaks from menu item Insert/Page Break. In Mathematica 6 (or later) , can also remove pagebreaks by deleting pagebreaks bar across screen if it is displayed by File/Printing Settings/Show Page Breaks.
FIXING COMMON MATHEMATICA ERRORS Use curly brackets "{" and "}" to enclose a list or group of similar objects in commands, and use square brackets "[" and "]" to enclose arguments of functions or the entire set of objects or arguments appearing in a command.
When define an explicit function such as F[x_]:= Tan[x]/x or F[x_]= Tan[x]/x or G[x_,y_]:= y*Sin[x], etc., be sure to use an underscore after each argument on the left hand side (and never on the right hand side!).
Be careful about multiple uses of expressions containing variables whose values are changed. Fewer problems are likely to occur if use delayed assignment ":=" in defining functions or if evaluate an expression with the substitution command as in "f/. x->a".
Be careful about missing "}" or ";" or "]" in Do Loops, missing "," and "]" in Print statements, and "}", "{" and "," in lists.
If Mathematica's instruction alignment in a block of commands looks bad, one of the above rules is probably being violated.
If Mathematica gives error message about Tags and Protected quantities, check for violations of above rules.
Empty plots or plot error messages such as "f is not a machine-size real number at x=..." are often due to undefined variables, or a missing "," or ";" separator. Examples include typographical errors, functions that have not been defined, variables that have not been specified in the expression to be plotted, an expression to be plotted that has an imaginary part, or a set of commands inside a Do Loop in which a Print statement is immediately followed by a Plot command without the appropriate "," or ";" separator between them.
An error message that some numerical string "is not a valid variable" occurs when a function cannot be evaluated for the chosen value of the variable. This may occur if a function or expression contains operations like derivatives or integrals and/or the ":=" construction is used in defining such functions or expressions. For example, if F[x_]:= D[Sin[x], x] and the value at x=2 is desired, entering F[2] returns a meaningless result, and Plot[F[x], {x, 0, 10}] and Table[F[x], {x, 0, 10, 0.1}] also fail. To find F[2], enter F[x]/.x->2 or enter x=2 followed by the command Evaluate[F[x]]. To make plots or tables of F[x], replace F[x] by Evaluate[F[x]] in the argument of the Plot or Table commands. (See Caution on evaluating or plotting in Functions section.)
Mathematica error messages containing "shadowing" or "symbol used in multiple contexts" occur if a symbol or name "X" is used before loading a package that contains "X" as the name of a defined function. Example: "X" ="Grad", where "Grad" is defined in a command line, and afterwards the vector analysis package is loaded. In this case, the vector-analysis package definition of "Grad" will over-write the previous one. If resulting complications are severe, a brute-force fix is to quit Mathematica, re-launch it, and load package correctly at start of new session. Once package is loaded, "X" will be protected from subsequent conflicting uses. Be careful loading packages: The correct syntax is <<PackageName` or Needs["PackageName`"].
CAUTION ON MATHEMATICA'S EVALUATION OF INTEGRALS CONTAINING SYMBOLIC PARAMETERS Sometimes (hopefully only rarely) a definite integral that has a symbolic parameter in its upper or lower limits of integration or that contains a symbolic parameter in its integrand may be evaluated incorrectly by Mathematica in the following sense: The integral evaluates to an inverse trig function or other multi-branch function and Mathematica fails to take (or to specify) the correct branch of the function. This can be regarded either as a "bug" or a failure of the Assumptions-option to pick out the correct solution.
An example of this is the integral of 1/(2 + Cos[y]) from y=0 to y=x, where x is a real symbolic parameter in the upper limit and x>Pi. Mathematica's result for the integral involves the ArcTan function, but by taking the wrong branch of the ArcTan function, Mathematica obtains a discontinuous function of x, whereas the integral must be continuous in x. Further details are at www.uwm.edu/~sorbello/classes/mathematica_badintegral.pdf.
In general, one should be careful to take the correct branch of any multi-branch function that appears in the output of Mathematica's Integrate command (or of any other command for that matter). As a precaution, it is advisable to plot Mathematica's result as a function of the symbolic parameter, and see if the result is consistent with the analytic properties of the integral. In the previous example, Mathematica's error can be corrected by simply adding appropriate constants in piecewise regions of parameter space to get the appropriate branch of the ArcTan function.
____________________________
ABOUT THIS DOCUMENT: This webpage is a continually updated list of Mathematica commands, examples, tricks and Mathematica frustration-avoidance measures that I have found useful over the years in my work as a physicist and teacher. It is intended to be a quick-reference help-file that one might consult instead of, or prior to, accessing Mathematica's extensive Help menu or Wolfram's on-line Documentation Center. I am posting this so that my students and I, and anyone else who may find it useful, can access it from the web, do browser word-searches on subjects within this document, and copy/paste examples directly into an ongoing Mathematica session. The order of subjects listed is intended to reflect roughly the order of commonly referenced subjects.This document can be located by Googling "sorbello mathematica" or, apparently, "mathematica frustration". For Mathematica beginners, I have also posted a bare-bones guide to Mathematica at www.uwm.edu/~sorbello/classes/mathematica_primer.pdf.
Prof. Richard S. Sorbello Department of Physics University of Wisconsin-Milwaukee Milwaukee, WI 53211 Email: sorbello@uwm.edu Updated: Jan 06, Nov 06, Jun 07, Nov 07, Dec 07, Mar 08, Feb 09, Mar 09, Apr 09