You may
copy-and-paste boldface code on this page directly into Mathematica.
If you have trouble running some samples, select the text here, copy, go to Mathematica,
and choose "Paste As...Plain Text" from the "Edit"
menu or right-click menu.
Use Alt-Tab to quickly flip between Mathematica and your
Internet browser.
Contents:
Basic
Calculations
Simplifying and
Solving Equations
Defining a Function
Graphing Curves and Surfaces
Basic Animation
Graphing Coordinate
Points
Bar Graph
Pie Chart
Note: Mathematica gives you exact answersfractions and reduced roots.
To get a numerical approximation use the function: N[expression]
or expression //N
Example: N[Pi] or N[Pi, 50] to approximate pi to 50
decimal places.
Simplifying
Expand[(x+3)(x-4)]
Factor[x^2 - x - 12]
Cos[x] / Tan[x] - Sin[ArcCos[x]]
Solving Be sure to use two equals signs.
Solve[x + 4 == 2x - 3]
Solve[x^2 + 5x + 7 == 0]
Solve[Log[2x] == 2Log[3x], x]
Solve[x + 4 - 3y == 2x - 3 + y/3, y] solves for y in terms of x.
Sometimes an error message is produced with your result: Solve[3^x == 5, x]
NSolve[3^x == 5, x] gives you a numerical approximation to the result.
Plot[Cos[x], {x, -Pi, Pi}]

Plot[x^2 - 3, {x, -4, 4}, PlotRange -> {-10, 10}]

Plot[{x, x^2, x^3}, {x, -1, 1}, PlotStyle -> {Thickness[.005], {RGBColor[1,0,0], Thickness[.01]}, Thickness[.02]}]

Graph with a Legend
To use this next sample, select the text, copy, go to Mathematica,
and choose
"Paste As...Plain Text" from the "Edit" menu or right-click
menu. You may also need to clear the memory for this one: Go to the "Kernel"
menu, choose "Quit Kernel...Local", and click "Ok."
<<Graphics`Legend`
f1[x_] = 2^x;
f2[x_] = 4^x;
f3[x_] = 7^x;
Plot[{f1[x], f2[x], f3[x]}, {x, -4, 0},
PlotStyle -> {Dashing[{.01}], Dashing[{.03}], Dashing[{.05}]},
PlotLegend -> {"f1", "f2", "f3"}, LegendPosition ->
{1, -0.2}]

In three dimensions:
Plot3D[y*Cos[x], {x, 0, 2Pi}, {y, -3, 3}]

To create an animation, be sure to use "Paste As...Plain Text"
<<Graphics`Animation`
SpinShow[Plot3D[y*Cos[x], {x, 0, 2Pi}, {y, -3, 3}, Boxed->False, Axes->False],
Frames -> 20, SpinRange -> {0 Degree, 360 Degree}]
Then double-click on any of the images. You may want to delete the first image for a smoother animation. It is just cycling through the list of images, like the frames of a movie.
You can show two graphs at the same time using "Show" in 2D or 3D.
graph1 = Plot3D[10 - x^2 - y^2, {x, -3, 3}, {y, -3, 3}];
graph2 = Plot3D[-3x + 2y + 6, {x, -3, 3}, {y, -3, 3}];
Show[graph1, graph2, PlotRange -> {0, 10}]



To use this sample, select the text, copy, go to Mathematica,
and choose
"Paste As...Plain Text" from the "Edit" menu or right-click
menu.
<<Graphics`;
BarChart[{10, 15, 13, 17}, {12, 14, 10, 14},
BarLabels->{"Qtr. 1", "Qtr. 2", "Qtr. 3", "Qtr.
4"},
BarStyle->{Hue[0], Hue[0.6]}, PlotLabel->"Homework Average",
DefaultFont->12];
ShowLegend[%, {{{Hue[0], " Per. 1"},{Hue[0.6], " Per. 2"}},
DefaultFont->12, LegendPosition->{1, -0.5}}]

To use this sample, select the text, copy, go to Mathematica,
and choose
"Paste As...Plain Text" from the "Edit" menu or right-click
menu.
<< Graphics`;
PieChart[{15, 10, 25, 50},
PieLabels -> {"Class Work", "Projects", "Homework",
"Tests and Quizzes"},
PieStyle -> {Hue[0.2], Hue[0.4], Hue[0.55], Hue[0.82]},
PlotLabel -> "Grading Categories", DefaultFont -> 14]

Derivatives
Taking a Derivative: D[3x^2
+ Sin[x] , x]
Don't forget to specify the variable of differentiation!
Second Derivatives: D[D[5x
E^(x^3/2), x], x]
Integrals
Taking an Antiderivative: Integrate[3x^2 + Sin[x] , x]
Finding a Definite Integral: Integrate[3x^2 + Sin[x] , {x, -1, Pi/2}]
Approximate this result: N[%] or use
NIntegrate[expression]
Limits
Finite Limit:
Limit[(x^2-9)/(x-3), x -> 3]
Limit at Infinity:
Limit[(4x^3 - 2x)/(5x^3 + 3x^2), x -> Infinity]
Limit at Negative Infinity: Limit[Sqrt[4x^2]/x, x ->
-Infinity]
Limit from the Left:
Limit[1/x, x
-> 0, Direction -> 1]
Limit from the Right: Limit[1/x,
x -> 0, Direction -> -1] (Default)
Infinite Series
Convergent:
Sum[1/n^2, {n, 1, Infinity}]
Numerical Approx.: NSum[1/n^2,
{n, 1, Infinity}]
Divergent:
Sum[1/n, {n, 1, Infinity}]
Try www.Wolfram.com, the publishers of Mathematica.
Extensive demos and ideas may be found at: http://library.wolfram.com.
Technical Support: http://www.wolfram.com/services/techsupport
E-mail Abby: abby.brown@sduhsd.net.
Abby Brown ~ Spring 2002