# MATLAB R2015a Experiences

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

$z=f(x,&space;y)$$f(x,&space;y)=x^2&space;+&space;y^2$

at $P=(2,&space;2,&space;8)$

To define this function in MATLAB (“MAT” comes from MATrix not “MATH”!) such  $-10&space;\leq&space;x&space;\leq&space;10,&space;y&space;=&space;x^T$ 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.

Example:

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 $\frac{\partial&space;z}{\partial&space;x}=2x,&space;\frac{\partial&space;z}{\partial&space;y}=2y$ For $P$ one has $\frac{\partial&space;z}{\partial&space;x}=4,&space;\frac{\partial&space;z}{\partial&space;y}=4$

The tangent plane at $P$ is then

$z&space;-&space;8&space;=&space;4&space;(x&space;-&space;2)&space;+&space;4&space;(y&space;-&space;2)$

or

$z&space;=&space;4x&space;+&space;4y&space;-&space;8$

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:

Another example:

To plot the Jacobian
$J=\begin{pmatrix}\frac{\partial&space;z}{\partial&space;x}&\frac{\partial&space;z}{\partial&space;y}\end{pmatrix}=\nabla&space;f(x,&space;y)$
evaluated at [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!