Directional Derivatives and the Gradient

Remember to do load(vect) if you haven't already during the session. By default Maxima assumes that the coordinate system is rectangular (cartesian) in the variables $x$, $y$, and $z$. If you do not want that then you need to change it by means of the scalefactors command.

Given the function of two variables, $f(x,y)=\mathrm{e}^{x^2} \sin y$.


\begin{maximasession}
f(x,y) := exp(x^2) * sin(y);
\maximaoutput*
\i1. f(x,y) :=...
...\\
\o1. f\left(x , y\right)\mathbin{:=}\exp x^2 \sin y \\
\end{maximasession}

We change to the correct coordinate system.


\begin{maximasession}
load(vect);
scalefactors([x,y]);
\maximaoutput*
\i2. load(...
...{}} \\
\i3. scalefactors([x,y]); \\
\o3. \mathbf{done} \\
\end{maximasession}

Next we find the gradient.


\begin{maximasession}
gdf: grad(f(x,y));
ev(express(gdf), diff);
define(gdf(x,y)...
...=}\left[ 2 x e^{x^2} \sin y , e^{x^2} \cos y \right] \\
\end{maximasession}

The directional derivative of $f$ at the point $(1,2)$ in the direction of the vector $\mathbf{v} = \langle 3,4 \rangle$ is


\begin{maximasession}
v: [3,4];
(gdf(1,2) . v)/sqrt(v . v);
ev(%, diff);
float(%...
...over{5}} \\
\i10. float(%); \\
\o10. 2.061108499400332 \\
\end{maximasession}

We know from our theory that the directional derivative is maximized when $\mathbf{v}$ points in the direction of the gradient, and the maximum value is the length of the gradient vector. Let's see just how big that is.


\begin{maximasession}
sqrt(gdf(1,2) . gdf(1,2));
float(ev(%, diff));
\maximaoutp...
...\
\i12. float(ev(%, diff)); \\
\o12. 5.071228088168654 \\
\end{maximasession}



G. Jay Kerns 2009-12-01