A Review of Useful Mathematica Commands

To plot the graph of the function y = sin(2x) + ln x, in the interval (1,5):

```
Plot[Sin[2x]+Log[x], {x, 1, 5}]
```

To label this graph:

```
Show[%, PlotLabel-> "Midshipman Joe Smith, 979797"]
```

To draw several graphs on the same screen:

```
Plot[Evaluate[Table[Sin[i x], {i, 1, 3}]], {x, -2 Pi, 2 Pi}]
```

To plot snapshots of a function of two variables (such as
u(x,t), where u is the temperature profile of a rod at x at
time t):

```
u[x_, t_] = Exp[-Pi t] Sin[Pi x/3];

Plot[Evaluate[Table[u[x, t], {t, 0, 1, 0.1}]], {x, 0, 3}]
```

To plot u(x,t), when u is found using the method of separation
of variables (e.g., u(x,t) = sum from i=1 to 20 of 1/i exp(-pi i t)
sin(pi i x/3)):

```
u[x_, t_] = Sum[1/i Exp[-Pi i t] Sin[Pi i x/3],{i, 20}];

Plot[Evaluate[Table[u[x, t], {t, 0, 1, 0.1}]], {x, 0, 3}]
```

To solve the system of differential equations
x' = sin x cos y, y' = -0.1 y- cos x sin y,
x(0) = 1, y(0) = -1,
for t in the interval (0, 20):

```
sol = NDSolve[{x'[t] == Sin[x[t]] Cos[y[t]],

y'[t] == -0.1 y[t]- Cos[x[t]] Sin[y[t]],

x[0] == 1, y[0] == -1}, {x, y}, {t, 0, 20}];

ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 20}]
```

To draw contours of a function of two variables (e.g.,
f(x,y) = sin 3x cos 2y):

```
ContourPlot[Sin[3 x] Cos[2 y], {x, -1, 1}, {y, -1, 1}]
```

To get levels with smoother boundaries:

```
ContourPlot[Sin[3 x] Cos[2 y], {x, -1, 1}, {y, -1, 1},

PlotPoints->40]
```

To draw a line between two points (0, 1) and (-1, 2):

```
Show[Graphics[Line[{{0,1},{-1,2}}]]]
```

To draw a line between the two points (0,1,0) and (-1, 2, 2):

```
Show[Graphics3D[Line[{{0,1,0}, {-1,2,2}}]]]
```

To draw a vector field (such as v = <y, -x>):

```
<<Graphics`PlotField`

a=PlotVectorField[{y, -x}, {x, -1, 1}, {y, -1, 1}]
```

To combine the above vector field with the contours of its
associated stream function psi = 1/2(x^2 + y^2):

```

b=ContourPlot[-1/2(x^2+y^2), {x, -1, 1}, {y, -1, 1}];

Show[b,a]
```