Plotting of a function of 3 variables

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 Comment

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.

Sign in to comment.

Answers (1)

Thorsten
Thorsten on 14 Feb 2013
Edited: Thorsten on 14 Feb 2013
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

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!