Plotting Gradient of a 3-variable Function

3 vues (au cours des 30 derniers jours)
NegIn
NegIn le 10 Avr 2022
Modifié(e) : Torsten le 10 Avr 2022
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?

Réponses (1)

Torsten
Torsten le 10 Avr 2022
Modifié(e) : Torsten le 10 Avr 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:

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by