show gradient vectors orthogonal to level curves



Dear Maxima list,

I am trying to demonstrate that gradient vectors are orthogonal to
contour lines.  I have tried lots of things, but nothing seems to be
exactly right.  Here's some of what I tried.

1) I can get plotdf to plot the vector field nicely, but then I can't
seem to add the contour lines to the plot... it is an ODE plot, after
all, which is concerned with trajectories and the like.

2) Using the draw package, I can plot both the vector field and the
contour lines in both 2D  and 3D.  I can use multiplot_mode to
superimpose plots.

2a) The axes do not align correctly in 2D because the contour plot
places a legend on the right top corner.  There is apparently some
rescaling for that and I cannot get the vector field plot to do
similar rescaling.  Furthermore, I cannot get the legend turned off of
the contour plot.

2b) The plots do not line up correctly in 3D because when contour =
base the contour lines are plotted on some low plane parallel to the
xy-plane which is out of reach.

Here is a minimal example of what I am talking about.


f(x,y) := x^2 - y^2;

define(fx(x,y), diff(f(x,y), x));
define(fy(x,y), diff(f(x,y), y));

load("draw");
coord: setify(makelist(k,k,-3,3))$
points2d: listify(cartesian_product(coord,coord))$
vf2d(x,y):= vector([x,y],[fx(x,y),fy(x,y)]/10)$
vect2: makelist(vf2d(k[1],k[2]),k,points2d)$

ex1: apply(gr2d, append([head_length=0.1, color=blue], vect2))$

ex2: gr3d(explicit(f(x,y),x,-3,3,y,-3,3),
      contour_levels = 15,
      contour        = map,
      surface_hide   = true) ;

multiplot_mode(screen);
draw(ex1);
draw(ex2);
multiplot_mode(none);



Any ideas?

Regards,
Jay


P.S.  You can get what I am looking for in Sage with

plot_vector_field(f.gradient(), (x, -3, 3), (y, -3, 3), aspect_ratio=1) +
contour_plot(f(x,y), (x, -3, 3), (y, -3, 3), fill=False, contours=9)




***************************************************
G. Jay Kerns, Ph.D.
Associate Professor
Department of Mathematics & Statistics
Youngstown State University
Youngstown, OH 44555-0002 USA
Office: 1035 Cushwa Hall
Phone: (330) 941-3310 Office (voice mail)
-3302 Department
-3170 FAX
VoIP: gjkerns at ekiga.net
E-mail: gkerns at ysu.edu
http://people.ysu.edu/~gkerns/