I look forward to get a MATLAB license after using the R2015a trial for a week. Scalar and vector functions, gradient fields, and level curves are very easy to be evaluated in my experience. Example:
Let’s plot the linearization of the elliptic paraboloid
To define this function in MATLAB (“MAT” comes from MATrix not “MATH”!) such we type
[x, y] = meshgrid(-10.0: 1.0: 10.0) to get our working domain. The first argument is the minimum value for x, the third is the step size and the last is the maximum value. If we ommit the middle parameter then the step size becomes 1 by default. For the ones confused about this script output: this grid is a collection of 2D vector pairs. After this script is executed the y 20×20 matrix will be equal the transpose of x 20×20 matrix.
The version of MATLAB I’m using doesn’t allow us define a function. However we can bypass this by evaluating our function at x and y using
z = x.^2 + y.^2. Then we can plot
(x, y, z) typing
mesh(x, y, z). We have now the following graph:
What about two plots on the same image? Fortunately this is done by using the
hold on and
hold off commands.
To plot level curves we type
contour(x, y, z). So, by typing
hold on; mesh(x, y, z); contour(x, y, z); hold off; we have the graph below.
For the function initially given For one has
The tangent plane at is then
In the console we then run
w = 4 * x + 4 * y - 8. Then if we execute
hold on; mesh(x, y, z); mesh(x, y, w); hold off; then we get:
To plot the Jacobian
[x, y] then we execute
[u, v] = gradient(z). This will make essentially the same as
meshgrid but now with u and v holding the computed (2D) gradient vectors. We can now plot these vectors on the x-y plane using
quiver(x, y, u, v). Finally, we can plot the curve levels, gradient vectors, and the function, on the same image by typing
hold on; mesh(x, y, z); contour(x, y, z); quiver(x, y, dx, dy); hold off; which generates a nice graph in my opinion:
That’s all. This post was basically a brief review on using MATLAB to plot some calculus functions. When I get the full version and if I the time allows me, I promess to bring more MATLAB simulations. Cheers!