0
|
3377 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# How to properly compute the gradient of a vector function ?

Posted 10 years ago
 Hi,I have a vector field function of the formu[p_] := p*Tanh[Norm[p]/2]/Norm[p]now i plot that function using for x=-5..5 and fixing y=2 and z=1Plot[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 usingPlot[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 messageGeneral::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
2 Replies
Sort By:
Posted 10 years ago
 ah i see. thank you very much Posted 10 years ago
 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.