# Mathematica

• The Mathematica lab is here. The assignment is at the end of the lab.
• Here is an example on how to check a PDE with mathematica.
 ```f[t_,x_]:=(1/Sqrt[t])*Exp[-x^2/(4t)]; FullSimplify[D[f[t,x],t] == D[f[t,x],{x,2}]] ```

Graphs and contour plots of functions of two variables
Please distinguish "graph", "contour curve", "contour surface", "contour map". Mathematica does this also nicely: If you do not specify a value in Contour Plot, it produces a contour map (several surfaces).
```f[x_, y_] := x^2 + y^2;
ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}]
Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}]
ContourPlot3D[ z - f[x, y], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]
ContourPlot3D[f[x, y] == 1, {x, -2, 2}, {y, -2, 2}]
ContourPlot3D[z - f[x, y] == 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]
```

## Lagrange problems

Solve a Lagrange problem with 2 variables
```f=2x^2+4 x y;  g=x^2 y;
Solve[{D[f,x]==L*D[g,x],D[f,y]==L*D[g,y],g==1},{x,y,L}]
```
With 3 variables:
```f=2x^2+4 x*y+z;     g=x^2 y + z;   c=1;
Solve[{D[f,x]==L*D[g,x], D[f,y]==L*D[g,y], D[f,z]==L*D[g,z], g==c},{x,y,z,L}]
```
With 3 variables and two constraints
```f=x y z;  g=x*y+2 y z+2 x z;  h=2x+2y+4z; d=4; c=1
Solve[{D[f,x]==L*D[g,x] + M*D[h,x],
D[f,y]==L*D[g,y] + M*D[h,y],
D[f,z]==L*D[g,z] + M*D[h,z],
g==c, h==d},{x,y,z,L,M}]
```

## Classifying critical points

Here is example code on how to compute the gradient and the discriminant
```f=x^3 y^3- x y^2;
D[f,{x,2}]*D[f,{y,2}]-D[f,{x,1},{y,1}]^2
```

## Classifying critical points

This produces a nice table.
```f=4 x y - x^3 y - x y^3;
ClassifyCriticalPoints[f_,{x_,y_}]:=Module[{X,P,H,g,d,S}, X={x,y};