Plotting of a function of 3 variables
Afficher commentaires plus anciens
Hello everybody
I'm trying to plot a graph of potential,V VS x,y,z coordinates.
Does anyone know how to do this?
I have tried surf and isosurface but does not work.
clear;
G=6.67;
m1=5;
m2=2;
mu=m2/(m1+m2);
omega=0.5;
a=10;
x=[0:1:100];
y=[0:1:100];
z=[0:1:100];
for i=1:length(x)
for j=1:length(y)
for k=1:length(z)
V(i,j,k)=(-G*m1/(sqrt(x(i)^2+y(j)^2+z(k)^2)))+(-G*m2/(sqrt((x(i)-a)^2+y(j)^2+z(k)^2)))-0.5*(omega^2)*(x(i)-mu*a)^2+y(j)^2;
end
end
end
1 commentaire
José-Luis
le 14 Fév 2013
You are trying to plot 4-dimensional data. Surf and isosurface are not going to work. What you could do is use scatter3 and color code you plot.
Réponses (1)
One way is to look at 3 cross-sections along the main axis
for i = 1:50:100
mesh(V(:, :, i), 'EdgeColor', 'k')
if i == 1, hold on, end
zlabel('z', 'Color', 'k', 'FontWeight', 'bold', 'Rotation', pi/2)
end
for i = 1:50:100
mesh(shiftdim(V(:, i, :), 2), 'EdgeColor', 'r')
ylabel('y', 'Color', 'r', 'FontWeight', 'bold')
end
for i = 1:50:100
mesh(shiftdim(V(i, :, :), 1), 'EdgeColor', 'b')
xlabel('x', 'Color', 'b', 'FontWeight', 'bold')
end
Catégories
En savoir plus sur Particle & Nuclear Physics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!