Preface


This is a tutorial made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in normal font. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the second course APMA0330
Return to Mathematica tutorial for the first course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330
Return to Part I of the course APMA0330

Labeling Figures


Label lines:

To see the equation of the line when cursor reaches the graph, use Tooltip command:

Plot[Tooltip[Sin[x]], {x, 0, 8 Pi}]

To put text/title on the picture, use Epilog command:

Plot[Sin[x], {x, 0, 8 Pi}, Epilog -> Text["My Text", Offset[{32, 0}, {14, Sin[14]}]]]

To write labels on the graph:    

fns[x_] := {1 + x^3, 2 + 8*x};
len := Length[fns[x]];

Plot[Evaluate[fns[x]], {x, 0, 6}, Epilog ->
Table[Inset[
Framed[DisplayForm[fns[x][[i]]], RoundingRadius -> 5], {5,
fns[5][[i]]}, Background -> White], {i, len}]]

You can do something similar with Locators that allows you to move the labels wherever you want:

fns[x_] := {Log[x], Exp[2*x], Sin[4*x], Cos[6*x]};

DynamicModule[{pos = Table[{1, fns[1][[i]]}, {i, len}]},
LocatorPane[Dynamic[pos], Plot[Evaluate[fns[x]], {x, 0, 1.8}],
Appearance ->
Table[Framed[Text@TraditionalForm[fns[x][[i]]],
RoundingRadius -> 5, Background -> White], {i, len}]]]
Export["label2.png",%]

 

Plotting with axes, without axes


There are times when the axes could interfere with displaying certain functions and solutions to ODEs. Fortunately, getting rid of axes in recent versions of Mathematica is very easy.
One method of specifying axes is to use the above options, but there is also a visual method of changing axes. Let us plot the function \( f(x) = 2\,\sin 3x -2\,\cos x \) without ordinate but using green color and font size 12 for abscissa:

f[x_] = 2*Sin[3*x] - 2*Cos[x]
Plot[f[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Blue}, Axes -> {True, False}, AxesStyle -> Directive[Green, 12]]
One can also use different colors and fonts for different axes
Plot[f[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Blue}, Axes -> {True}, AxesStyle -> {Directive[Green, 12], Red}]

We can plot two graphs in the same figure:

Plot[{-1, 1} Sqrt[1 - x^2], {x, -1, 1}, PlotStyle -> {Thickness[0.007], Black}, AspectRatio -> Automatic, PlotLabel -> "Circle", LabelStyle -> Directive[Orange, Italic]]
You can also label the graph with Epilog option:
Plot[{-1, 1} Sqrt[1 - x^2], {x, -1, 1}, PlotStyle -> {Thickness[0.007], Black}, AspectRatio -> Automatic, Epilog -> Text[Style["Circle", FontSize -> 16], {0.6, 0.4}]]

We can also add title in different styles:
Plot[f[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Blue}, Axes -> {True},
AxesStyle -> {Directive[Green, 12], Red}, PlotLabel -> 2*Sin[3*x] - 2*Cos[x]] Plot[f[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Blue}, Axes -> {True},
AxesStyle -> {Directive[Green, 12], Red},
PlotLabel -> Style[Framed[2*Sin[3*x] - 2*Cos[x]], 16, Black, Background -> Lighter[Yellow]]]

 

We show how to present data using GraphicsGrid command:
GraphicsGrid[ Partition[ Table[Show[CountryData[c, "Flag"], PlotLabel -> c], {c, Take[CountryData["Europe"], 16]}], 4]]

 

 

Discontinuous Functions

Direction Fields

Implicit Plot

Parametric Plot

Labeling Figures

Figures with Arrows

Electric circuits

Plotting with Filling

Polar Plots

Some Famous Curves

Cycloids

 

Return to Mathematica page

Return to the main page (APMA0330)
Return to the Part 1 (Plotting)
Return to the Part 2 (First Order ODEs)
Return to the Part 3 (Numerical Methods)
Return to the Part 4 (Second and Higher Order ODEs)
Return to the Part 5 (Series and Recurrences)
Return to the Part 6 (Laplace Transform)