Help plotting equations in 3D
1 回表示 (過去 30 日間)
古いコメントを表示
Joseph Nettesheim
2015 年 8 月 25 日
コメント済み: Joseph Nettesheim
2015 年 8 月 26 日
I am looking to plot the following in MATLAB to create a figure similar to the picture attached.

The equations are:
x=a*cos(phi);
y=a*sin(phi);
z=sqrt((c.^2./(r-(x.^2 + y.^2))).*(r-((1+epsilon).*(x.^2 + y.^2))));
where r=(a-A.*((y.^2.*(3.*x.^2-y.^2))./(x.^2+y.^2)).^B).^2;
And constants are:
a=1;
A=0.1339;
B=0.397;
c=1;
phi=0:0.001:2*pi;
epsilon=10.^-5;
NOTE: The original z equation is attached (I just solved for z and made a variable r to save space):

I have tried using plot3(X,Y,Z) using
[X,Y]=meshgrid(x,y);
z=peaks(6284);
because I found something similar in another tread.
The result is:

I appreciate any help you can offer!
2 件のコメント
Star Strider
2015 年 8 月 25 日
The plot3 function requires three column vectors for its arguments. It doesn’t use meshgrid.
It will help if you post your code, or attach it if it is longer than about 20 lines. (Use the ‘paperclip’ icon and complete both steps.)
採用された回答
Mike Garrity
2015 年 8 月 25 日
Actually, I feel like we're missing a piece of the question here.
In your code, meshgrid and peaks(6284) are creating 2D arrays. That's what you want when you're drawing a parametric surface where each point is a function of 2 parameter values. But it doesn't look like you've got a parametric surface.
From the picture, it kind of looks like you're trying to draw a parametric curve where each point is a function of a single parameter value (perhaps phi?). In that case, you're going to be generating 1D arrays for your X, Y, and Z coordinates. As Star Strider and Walter said, once you have these 1D arrays, you're probably going to pass them to the plot3 function.
But that doesn't look like what you've got either. In your code, you're generating Z as a function of X and Y, rather than as a function of the parameter value phi. But that doesn't match your picture, because in your picture there are multiple Z values for the same X & Y pair.
On the other hand, your function actually looks like an implicit surface. This is where you're drawing a surface through all of the points where the left hand side of the equation are exactly equal to 1. But, if I code that up:
cla
n = 100;
[y,x,z] = ndgrid(linspace(-.5,.5,n), ...
linspace(-.5,.5,n), ...
linspace(-1,1,n));
r = (a-A.*((y.^2.*(3.*x.^2-y.^2))./(x.^2+y.^2)).^B).^2;
f = ((x.^2+y.^2)./r).*(1+epsilon-z.^2/c.^2) + z.^2./c.^2;
isosurface(x,y,z,f,1)
view(3)
camlight
xlabel('X')
ylabel('Y')
zlabel('Z')
Then I get this:

which doesn't look at all like your picture.
Perhaps you could give us a bit more background?
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
