Skip to main content

The gradient by definition is a vector formed by three directional derivatives, $\partial F/\partial x$∂F/∂x, $\partial F/\partial y$∂F/∂y and $\partial F/\partial z$∂F/∂z, so if you only need the $z$z component, at least we have two perspectives, which are, in order of recommendation:

1.- You can calculate it directly with diff(F,z). Check the docs https://www.mathworks.com/help/symbolic/differentiation.html

2.- Or you can calculate the directional derivative in the $z$z direction using fndir(F,Vz), where Vz is a vector in the desired direction, z in this case. Check the docs https://www.mathworks.com/help/curvefit/fndir.html

This perspectives have the advantage of being based on built in, optimized functions.

The gradient by definition is a vector formed by three directional derivatives, $\partial F/\partial x$, $\partial F/\partial y$ and $\partial F/\partial z$, so if you only need the $z$ component, at least we have two perspectives, which are, in order of recommendation:

1.- You can calculate it directly with diff(F,z). Check the docs https://www.mathworks.com/help/symbolic/differentiation.html

2.- Or you can calculate the directional derivative in the $z$ direction using fndir(F,Vz), where Vz is a vector in the desired direction, z in this case. Check the docs https://www.mathworks.com/help/curvefit/fndir.html

This perspectives have the advantage of being based on built in, optimized functions.

The gradient by definition is a vector formed by three directional derivatives, ∂F/∂x, ∂F/∂y and ∂F/∂z, so if you only need the z component, at least we have two perspectives, which are, in order of recommendation:

1.- You can calculate it directly with diff(F,z). Check the docs https://www.mathworks.com/help/symbolic/differentiation.html

2.- Or you can calculate the directional derivative in the z direction using fndir(F,Vz), where Vz is a vector in the desired direction, z in this case. Check the docs https://www.mathworks.com/help/curvefit/fndir.html

This perspectives have the advantage of being based on built in, optimized functions.

Source Link

The gradient by definition is a vector formed by three directional derivatives, $\partial F/\partial x$, $\partial F/\partial y$ and $\partial F/\partial z$, so if you only need the $z$ component, at least we have two perspectives, which are, in order of recommendation:

1.- You can calculate it directly with diff(F,z). Check the docs https://www.mathworks.com/help/symbolic/differentiation.html

2.- Or you can calculate the directional derivative in the $z$ direction using fndir(F,Vz), where Vz is a vector in the desired direction, z in this case. Check the docs https://www.mathworks.com/help/curvefit/fndir.html

This perspectives have the advantage of being based on built in, optimized functions.