Plotting Gradient of a 3-variable Function

3 次查看(过去 30 天)
I am trying to plot the gradient of a 3-variable function (the functions are all syms).
g = gradient (f, [AB, BC, AC])
I know the code for a two-variable looks like this:
[X, Y] = meshgrid(-1:.1:1,-1:.1:1);
G1 = subs(g(1),[x y],{X,Y});
G2 = subs(g(2),[x y],{X,Y});
quiver(X,Y,G1,G2)
How can I modify the code to be able to plot the 3-variable gradient?

回答(1 个)

Torsten
Torsten 2022-4-10
编辑:Torsten 2022-4-10
Depends on what you want to plot.
In each point (x,y,z), the gradient g=(gx,gy,gz) is a 3d-vector associated with this point.
But plotting 3d vectors attached to points in 3d-space won't give a reasonable plot in my opinion.
So without fixing a plane in which you want to see the gradient and maybe projecting the gradient onto this plane, you won't be able to visualize anything.
So you will first have to decide where and what you want to plot.
If you want to try a 3d-vector plot, use quiver3:

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by