how can we plot this function as 3d with matlab?

조회 수: 2 (최근 30일)
murat can
murat can 2012년 9월 12일
how can we plot this fucntion as 3d with matlab? I tried surf and ezplot to plot function. but they didnt work. thanks for help.

채택된 답변

Matt Tearle
Matt Tearle 2012년 9월 12일
Aww, cute.
The reason you can't use surf or ezplot is that these are not designed for this kind of equation. To use surf you need to have a surface defined as z = f(x,y). You have g(x,y,z) = 0. If you could rearrange that into z = f(x,y), you could use surf, but the equation you have doesn't really allow that.
So... instead, go back to the definition of the surface as g(x,y,z) = 0. Think of this as a particular isosurface of the function g(x,y,z) (with isosurface value of 0).
To make a surface in MATLAB from that kind of setup, you need (surprise, surprise) isosurface. Look in the documentation at the examples for isosurface. They will guide you through the visualization.
The one thing you need that isn't in the isosurface doc is to create the data to plot. (The examples do [x,y,z,v] = flow; which creates the data from a canned routine for a specific example.) So:
  1. You need to create 3 3-D arrays for x, y, and z, in the given range -- hint: linspace and meshgrid.
  2. Then you need to evaluate the function g(x,y,z) at each of those x, y, z locations: V = (X.^2+9*Y.^2/4+Z.^2-1).^3 - X.^2.*Z.^3 (etc)
Now you have the data, you can plot, using the examples in the isosurface documentation.
You'll "love" the result. Haha. I'm so funny.
  댓글 수: 6
Sean de Wolski
Sean de Wolski 2012년 9월 12일
@Azzi - no you don't!
isosurface is essentially a three dimensional contour plot. When you set the threshold value to zero, it will draw the isosurface at that interface thus automagically solving the equation for you :)
Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 12일
Ok Sean, I widhdraw

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 12일
편집: Azzi Abdelmalek 2012년 9월 12일
sol=[];
for k=-3:0.1:3
for m=-3:0.1:3
x=[k m];
a=x(1)^2+x(2)^2*9/4-1;
v=[1 0 3*a 0 + 3*a^2 0 a^3 ];
z=roots(v);
z=z(imag(z)==0);
n=length(z);
if n>0
xyz=[repmat(x(1:2),n,1) z];
sol=[sol;xyz];
end
end
end
plot3(sol(:,1),sol(:,2),sol(:,3))

murat can
murat can 2012년 9월 12일
i did something again but it didnt work again... =)
clear all
close all
syms X Y Z V
[X,Y,Z] = meshgrid(linspace(-3,3,25));
V = (X.^2+9*Y.^2/4+Z.^2-1).^3 - X.^2.*Z.^3
fv=isosurface(X,Y,Z,V,0)
fv = isosurface(V,0)
fvc = isosurface(V,'red')
p = patch(isosurface(X,Y,Z,V,-0))
isonormals(X,Y,Z,V,p)
set(p,'FaceColor','red','EdgeColor','none');
view(3);
axis tight
camlight
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2012년 9월 12일
편집: Sean de Wolski 2012년 9월 12일
You don't need to define X,Y,Z,V as syms since they won't be syms but rather double arrays....
Removing that line, it works for me.
murat can
murat can 2012년 9월 12일
its excess. i will delete it. i tought i was need it for equation.
i tried another way. i forgot to delete it. thx for remember.

댓글을 달려면 로그인하십시오.


murat can
murat can 2012년 9월 12일
for axises i used daspect([1 1 1]) and it worked fbetter i think ^^ thank you all for help.
clear all
close all
syms X Y Z V
[X,Y,Z] = meshgrid(linspace(-3,3,25));
V = (X.^2+9*Y.^2/4+Z.^2-1).^3 - X.^2.*Z.^3
fv=isosurface(X,Y,Z,V,0)
fv = isosurface(V,0)
fvc = isosurface(V,'red')
p = patch(isosurface(X,Y,Z,V,-0))
isonormals(X,Y,Z,V,p)
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])
view(3);
axis tight
camlight
and the result is good. to see results: http://postimage.org/image/6altq3zqf/

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by