Message Boards Message Boards

0
|
3483 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to properly compute the gradient of a vector function ?

Posted 10 years ago
Hi,

I have a vector field function of the form
u[p_] := p*Tanh[Norm[p]/2]/Norm[p]

now i plot that function using for x=-5..5 and fixing y=2 and z=1
Plot[u[{x, 2, 1}], {x, -5, 5}]

and i get the expected plot with 3 curves (since u returns a 3-vector)

now i wanna plot the gradient of it with respect to the x-axis using
Plot[Grad[u[{x, 2, 1}], {x}], {x, -5, 5}]

or alternatively
f[{x_, y_, z_}] := Grad[u[{x, y, z}], {x}]
Plot[f[{x, 2, 1}], {x, -5, 5}]

but in both cases it will fail with the error message
General::ivar: -4.9998 is not a valid variable. >>
General::ivar: -4.79571 is not a valid variable. >>
General::ivar: -4.59163 is not a valid variable. >>


what do i do wrong ? can anybody help out ?

cheers
POSTED BY: xort dsc
2 Replies
Posted 10 years ago
ah i see. thank you very much emoticon
POSTED BY: xort dsc
Try the following:
Plot[Evaluate@
  Grad[Simplify[u[{x, 2, 1}], x \[Element] Reals], {x}], {x, -5, 5}]
The Simplify is so that the Norm will evaluate without annoying derivatives of the Abs function.  The Evaluate is so that the argument of the Plot is computed before the Plot tries to evaluate it numerically.  Otherwise Plot will put in a value of x first and then attempt to compute the Grad.  This is why you saw those numerical warnings.
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract