0
votes

I have a simple Mathematica code below where I first introduce a scalar function ϕ = ϕ[x,y,z] and then calculate the gradient of ϕ. Now, I would like to evaluate the Gradient at point P by substituting in proper values for x, y, z. Please assist me with last step with plugging values into x and y into gradient. See code Below:

ϕ = y^2 + z^2 - 4;
varlist = {x, y, z}
Delϕ = Table[D[ϕ, varlist[[i]]], {j, 1, 1}, {i, 1, 3}]
Delϕ // MatrixForm
P = {2, 1, Sqrt (3)}

Thanks

2

2 Answers

1
votes

Assuming you meant y^2 + z^2 - 4 x

φ = y^2 + z^2 - 4 x;
varlist = {x, y, z};
g = D[φ, #] & /@ varlist

{-4, 2 y, 2 z}

p = {2, 1, Sqrt[3]};
grad = g /. Thread[varlist -> p]

{-4, 2, 2 Sqrt[3]}

1
votes

another approach is to make your derivative a function:

\[Phi] = y^2 + z^2 - 4 x;
varlist = {x, y, z};
Del\[Phi][{x_, y_, z_}] = Table[D[\[Phi], varlist[[i]]], {i, 1, 3}];

then you can simply do this:

P = {2, 1, Sqrt[3]};
Del\[Phi][P]

{-4, 2, 2 Sqrt[3]}