Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

General Mathematica Conventions

This document provides a quick reference to common commands and conventions in Mathematica. It summarizes key functions for evaluating expressions, plotting graphs, solving equations, working with matrices and lists, and using packages in Mathematica. The summary also highlights basic syntax rules and shortcuts for working efficiently in the Mathematica environment.

Uploaded by

Allen Smith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

General Mathematica Conventions

This document provides a quick reference to common commands and conventions in Mathematica. It summarizes key functions for evaluating expressions, plotting graphs, solving equations, working with matrices and lists, and using packages in Mathematica. The summary also highlights basic syntax rules and shortcuts for working efficiently in the Mathematica environment.

Uploaded by

Allen Smith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mathematica Quick Reference

General Mathematica Conventions then f[x] /. soln Eigensystem Eigensystem[m] gives a list {values,
will give {-9,7,-9}. vectors} of the eigenvalues and eigenvectors of the square
Shift-Enter evaluates a cell matrix m.
( ) are the only grouping symbol
[ ] are used for function arguments N and //
{ } are used for lists
A cell is not evaluated until you Shift-Enter that cell. N[ ] forces a numeric approximation of the argument. MatrixPower MatrixPower[mat, n] gives the n-th
Mathematica commands begin with a capital letter for N[π] is equivalent to π // N. matrix power of mat.
example sin(x) is entered as N[π,30] will give 30 digits of π.
Sin[x]
Do not use E as a variable since it is used as the constant
Integration Solve and NSolve
e. If you start your variables and definitions with a lower-
case letter then they will not conflict with Mathematica You can use the input palette to enter an integral as you
definitions. would see it in a Calculus book or you can use Solve[eqns, vars] attempts to solve an equation or set
% always stands for your last result. If you enter 2+2 and Integrate[f, {x, xmin, xmax}] of equations for the variables vars.
Shift-Enter the result will be 4. If you then enter % + 2 If you only need an approximation you can use Solve[{1 + x2 == 0, y 2 == x2 , z == x}, {x, y, z}]
the result will be 6. NIntegrate[f, {x, xmin, xmax}] Notice the double equal signs.
If you don’t need exact solutions to a polynomial you can
use
Sessions Lists NSolve[lhs==rhs, var] which gives a list of numerical
When you start Mathematica a session is started. Any approximations to the roots of a polynomial equation.
Lists are enclosed in { }. Let a={1,3,5}, then a[[2]]=3. FindRoot[lhs==rhs, {x, x0} searches for a numerical
functions you define, variable assignments you make, or Flatten[ ] un-nests one level.
packages you load are kept for that session. You should solution to the equation lhs==rhs, starting with x=x0.
Join[a,b] puts list a and list b together.
use the Clear[ ] command before you reuse variables. Union[a,b] puts list a and list b together, removes du-
plicates, and sorts the resulting list.
Palettes Simplify
Choose File then Palettes Matrices Simplify[expr] performs a sequence of algebraic trans-
The AlgebraicManipulation and BasicInput are use-
A formations on expr, and returns the simplest form it
ful.  matrix
 is represented as a list of lists.
a b finds.
is entered as {{a,b},{c,d}}
c d
Functions The command MatrixForm formats a matrix in the usual
form.
To enter f (x) = x2 + 3 in Mathematica Packages
IdentityMatrix[n] creates the n × n Identity Matrix
f[x ]:=x^2+3
Notice the on the left hand side and the := Some commands require the loading of a package before
Then entering f[2] will yield 7. Row Reduce RowReduce[m] gives the rowreduced they can be used.
form of the matrix m. <<package
Evaluate and /. If you forget to load the package first you can enter
Remove["Global`*"] (where ` is to the left of 1 and on
Matrix Multiply a.b.c gives products of vectors,
Evaluate[expr] causes expr to be evaluated. the same key as the tilde) or save your work, exit Math-
matrices and tensors. a,b,c must have appropriate di-
expr /. rules applies a rule or list of rules to transform ematica, and then open a new session.
mensions.
each subpart of an expression expr. For example you must enter
f[x ]:=x^4+4x^3-2x^2-12x << Graphics`ImplicitPlot`
soln = Solve[f’[x] == 0, x] Eigenvalue Eigenvalues[m] gives a list of the eigen- before using
yields {{x->-3},{x->-1},{x->1}} values of the square matrix m. ImplicitPlot[x^2 + 2 y^2 == 3, {x, -2, 2}]
Plotting Axis Labels NDSolve
The basic 2-dimension plot command is AxesLabel -> label specifies a label for the a axis of NDSolve[{y’[x]==1/(2y[x]),y[.01]==.1}
Plot[f[x],{x,-3,3}] a twodimensional plot, and the z axis of a threedimen- ,y,{x,.01,1}] numerically solves the BVP for x ∈
To plot two or more functions sional plot. (0.01, 1) the result is an interpolating function.
Plot[{f[x],g[x]},{x,-3,3}] AxesLabel -> {xlabel, ylabel, . . . } specifies la- If you want to graph the interpolating function you can
To specify the y axis from −2 to 5 use bels for different axes. use the following commands
Plot[f[x],{x,-3,3},PlotRange->{-2,5}] soln=
Three dimensional plotting is done by NDSolve[{y’[x]==1/(2y[x],y[.01]==.1},
Plot Points
Plot3D[f[x,y],{x,-3,4},{y,0,10}] y,{x,.01,1}];
Parametric plots are made by PlotPoints-> n specifies n points to be used in the Plot[Evaluate[y[x] /. soln], {x, .01, 1}]
ParametricPlot[{fx [t], fy [t]},{t,0,4}] plot. For a 3D plot this would specify n in both the x soln= names the interpolating function, Evaluate causes
ParametricPlot3D[{fx [t, u], fy [t, u], fz [t, u]} and y directions. the function to be evaluated and /. replaces y with the
,{t,0,4},{u,0,10},PlotPoints ->{3,20}] PlotPoints ->{nx,ny} specifies that nx points should interpolating function.
be used in the x direction and ny points in the y direction.
Color in plots Loops
Hue[ ] as the argument runs from 0 to 1, Hue[ ] runs Filled Plot For[i,i<5,i++, Print[i]] prints 1, 2, 3, 4. You can
through red, yellow, green, cyan, blue, magenta, and back place commands separated by ;
<< Graphics`FilledPlot`
to red again. Do[expr ,i,imin,imax,step]
FilledPlot[Sin[x], {x, 0, 2 Pi}]
Plot[{f[x],g[x]},{x,-3,3},
PlotStyle->{Hue[.3],Hue[.6]}] Table
plots f (x) in green and g(x) in blue. ListPlot
You can also use RGBColor[1,0,0] in place of Hue[1]. Table[Prime[i],{i,1,5}] yeilds
RGBColor[1,1,1] is white and RGBColor[0,0,0] is ListPlot[{y1, y2, . . . }] plots a list of values. The x {2,3,5,7,11} while
black. coordinates for each point are taken to be 1, 2,. . . . Table[Prime[i],{i,1,5,2}] yeilds
ColorFunction->Hue colors 3D plots. ListPlot[{{x1,y1},{x2,y2},. . .}] plots a list of values {2,5,11}
When using a large number of PlotPoints you may want with specified x and y coordinates.
to set Important Note
Mesh->False PlotJoined
Save often. Mathematica can crash and you will lose all
ListPlot[{y1, y2, . . . },PlotJoined->True] con- unsaved work.
Combining Plots
nects the points.
You can name plots with an assignment
a=Plot[f[x],{x,-3,3}]
ContourPlot
b=Plot[g[x],{x,-3,3}]
then Show[a,b] will combine the plots. ContourPlot[f, {x, xmin, xmax},
{y, ymin, ymax}] generates a contour plot of f as a
Display function function of x and y.

DisplayFunction allows you to suppress the display of


intermediate graphics. Differential Equations
plot1 = Plot[Sin[x], {x, 0, 2 Pi},
DisplayFunction->Identity]; DSolve
plot2 = Plot[Sin[2 x], {x, 0, 2 Pi},
DisplayFunction->Identity]; DSolve[y’[x] == 2 a x, y[x], x] yields
Show[plot1, plot2, {{y[x] -> a x^2 + C[1]}} To add initial conditions:
DisplayFunction->$DisplayFunction]; DSolve[{y’[x]==2 a x,y[0]==2}, y[x], x] yields
Will display one graph. {{y[x] ->2 + a x^2}}

You might also like