Plotting Gradient of a 3-variable Function
9 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Torsten
on 10 Apr 2022
Edited: Torsten
on 10 Apr 2022
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:
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!