All published worksheets from http://sagenb.org
Image: ubuntu2004
Gradients
Based on material from Ben Woodruff
It is simple to calculate the gradient of a function.
We can plot the gradient field easily as well.
We can also plot the level curves (i.e., a contour plot) on top of the gradient field, so that we can see that the gradient is always normal (i.e., perpendicular) to the level curve.
This all holds for functions from as well. However, in this case, the function has "level surfaces", and the gradient is a 3-dimensional vector.
Evaluate the cell below to get the plot_vector_field3d command, which allows us to plot this 3d gradient field.
You'll notice that the gradient vectors in the plot below are all perpendicular to the level surfaces.
Directional Derivatives
A directional derivative is just the gradient dotted with a unit vector in the direction. Remember to evaluate at the point.
To evaluate it at a point, just do the following. Literally, this is taking the first thing in point (the -coordinate) and making that the first argument of the function, and so on.
In the interact below, the directional derivative is the slope of the green tangent line. The cross-section in the direction is the red curve, and the gradient vector is the orange vector.
The 2nd Derivative test
The second derivative test looks at the eigenvalues of the Hessian matrix evaluated at critical points.
Color | Critical Point | Eigenvalue | Eigenvector |
---|---|---|---|
red | \left(0.0,0.0,0\right) | -2.0 | \left(1.0,0.0\right) |
blue | \left(0.0,0.0,0\right) | 2.0 | \left(0.0,1.0\right) |
Color | Critical Point | Eigenvalue | Eigenvector |
---|---|---|---|
red | \left(0.0,0.0,0\right) | 1.0 | \left(0.707106781187,0.707106781187\right) |
blue | \left(0.0,0.0,0\right) | -1.0 | \left(-0.707106781187,0.707106781187\right) |
red | \left(-1.22474487139,-1.22474487139,0.551819161757\right) | -0.735758882343 | \left(1.0,0.0\right) |
blue | \left(-1.22474487139,-1.22474487139,0.551819161757\right) | -0.735758882343 | \left(0.0,1.0\right) |
red | \left(1.22474487139,-1.22474487139,-0.551819161757\right) | 0.735758882343 | \left(1.0,0.0\right) |
blue | \left(1.22474487139,-1.22474487139,-0.551819161757\right) | 0.735758882343 | \left(0.0,1.0\right) |
red | \left(-1.22474487139,1.22474487139,-0.551819161757\right) | 0.735758882343 | \left(1.0,0.0\right) |
blue | \left(-1.22474487139,1.22474487139,-0.551819161757\right) | 0.735758882343 | \left(0.0,1.0\right) |
red | \left(1.22474487139,1.22474487139,0.551819161757\right) | -0.735758882343 | \left(1.0,0.0\right) |
blue | \left(1.22474487139,1.22474487139,0.551819161757\right) | -0.735758882343 | \left(0.0,1.0\right) |
Color | Critical Point | Eigenvalue | Eigenvector |
---|---|---|---|
red | \left(-0.666666666667,0.666666666667,6.2962962963\right) | -2.0 | \left(0.707106781187,-0.707106781187\right) |
blue | \left(-0.666666666667,0.666666666667,6.2962962963\right) | -6.0 | \left(0.707106781187,0.707106781187\right) |
red | \left(0.0,0.0,6\right) | 2.0 | \left(0.707106781187,-0.707106781187\right) |
blue | \left(0.0,0.0,6\right) | -2.0 | \left(0.707106781187,0.707106781187\right) |
Lagrange Multipliers
We'll work out an example problem.
Find the maximum and minimum temperatures on the circle if the temperature of a point is .
Another way to imagine it is just as the constraint function (the circle), drawn on the temperature function.
Calculate the Lagrangian . We'll use "lambda_" for because we can't use the word "lambda" in python/Sage (it means something different than what we want).
We get four solutions to the three equations given by .
Now let's plug each of these values in to to find the global maxima and minima.
The maximum is therefore at both and (max value ) and the minimum is at (min value 3).