       Re: How to plot divergence of gradient as contour plot

• To: mathgroup at smc.vnet.net
• Subject: [mg124035] Re: How to plot divergence of gradient as contour plot
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Fri, 6 Jan 2012 04:19:07 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201201051100.GAA14785@smc.vnet.net>

```You need to use the VectorAnalysis package (carefully!), remembering that:

(i) the default coordinate system is Cartesian[Xx, Yy, Zz]; and
(ii) the result of using that package's Grad, Div, Curl is _not_

-2 Sin[Xx + Yy]

ContourPlot[
Div[Grad[Sin[Xx + Yy]]] /. {Xx -> x, Yy -> y},
{x, -5, 5}, {y, -5, 5}]

(* or first define a function *)

f[x_, y_] := Div[Grad[Sin[Xx + Yy]]] /. {Xx -> x, Yy -> y}
ContourPlot[f[x, y], {x, -5, 5}, {y, -5, 5}]

I find the whole paradigm of the VectorAnalysis package to be
aggravatingly annoying. After all, from a mathematical perspective, if
you're given a scalar-valued function with vector inputs, then its
gradient is just a well-defined vector field -- and that has nothing
whatsoever to do with so-called "coordinate systems". That is, one ought
to be able to do something like this -- just like any standard modern
text on multivariable calculus would show:

phi[x_, y_] := Sin[x + y]

In Mathematica, with the VectorAnalysis defaults, you'd get 0 as result
there, since you didn't override the default variable names Xx, Yy, Zz.

Then there's the whole nonsense of the gradient other coordinate
systems. That, to my mind, is a very odd way to think about things.
Mathematically, given a scalar field, it has an associated gradient
vector field. Period. If you want to "express the gradient in terms of"
another coordinate system, you're no longer finding that gradient;
you're finding a composite of functions where you go first from that
other coordinate system to cartesian coordinates, next take the
gradient, and finally go back from cartesian coordinates in the result
to the other coordinate system.

(I trust others will disagree with the preceding argument!)

On 1/5/12 6:00 AM, Szymon Roziewski wrote:
> Hello there,
>
> I am concerning to plot something like that.
>
> ContourPlot[Divergence[Gradient[Sin[x + y]]], {x, -5, 5}, {y, -5, 5}]
>
> Plotting divergence of gradient scalar field.
> How can I manage to do that?

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

```

• Prev by Date: Re: Rule replacement doesn't work after NDSolve?
• Next by Date: Re: drawing polygon diagonals
• Previous by thread: Re: How to plot divergence of gradient as contour plot
• Next by thread: Re: How to plot divergence of gradient as contour