I would like to evaluate the gradient of a certain function at position (x0,y0,z0) where x0, y0, z0 are global variables which can get altered in real-time later in the worksheet. The only way I know of doing this, without pain, is using Dynamic (is there a better way?)
But there is something strange going on, Mathematica doesn't want to evaluate the components of my gradient vector into actual numbers.
f := z - x*y;
x0 = 1; y0 = 2; z0 = 1;
mygradient := {D[f, x], D[f, y], D[f, z]};
normalizedgrad := mygradient/Sqrt[mygradient.mygradient];
n := normalizedgrad //. {x -> Dynamic[x0], y -> Dynamic[y0], z -> Dynamic[z0]};
Now,
n
produces
{-2/Sqrt[1+3^2+2^2], -3/Sqrt[1+3^2+2^2], 1/Sqrt[1+3^2+2^2]}
and I am unable to numerically evaluate this. If I write
N[n]
then I just get back the same as n.
Dynamic[n]and dropDynamicfrom//.. Since you definenwithSetDelayedit will be up to date when requested andDynamic[n]will refresh based onx0value change etc. – Kuba Oct 23 '18 at 11:38