plot 3D fun in x, y and z

조회 수: 18 (최근 30일)
hend
hend 2017년 3월 28일
댓글: KSSV 2017년 3월 30일
i want to draw a function f varied in x, y and z such that f = xyz using matlab 2014a

답변 (2개)

John BG
John BG 2017년 3월 28일
Hi hend
since your function takes in all 3 coordinates, the only way to 'see' or plot the function is slicing the volume comprised by the domain used.
For such purpose the command slice comes really handy, have a look:
N=10
range=[-N:1:N]
[x,y,z] = meshgrid(range,range,range);
v = x.*y.*z;
figure
colormap hsv
for k = range
hsp = surf(linspace(-N,N,numel(range)),linspace(-N,N,numel(range)), zeros(numel(range)) + k);
rotate(hsp,[2,-2,2],15)
xd = hsp.XData;yd = hsp.YData;zd = hsp.ZData;
delete(hsp)
slice(x,y,z,v,[-N,N],2*N,-2*N) % static volume boundaries
hold on
h1=slice(x,y,z,v,xd,yd,zd) % this is the slicing plane
hold off
view(-5,10)
axis([-10 10 -10 10 -10 10])
drawnow
colorbar
end
note the handle h1 to pull the values on the slice plane, that may be useful to extract the slicing plane points with
Xslice=h1.XData
Yslice=h1.YData
Zslice=h1.ZData
the colour bar is also useful to visualise the actual value of the function.
if you find these lines useful would you please be so kind consider marking my answer as Accepted Answer?
To any other reader, if you find this answer of any help would you please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG

KSSV
KSSV 2017년 3월 28일
N = 10 ;
x = linspace(0,1,N) ;
y = linspace(0,1,N) ;
z = linspace(0,1,N) ;
[X,Y,Z] = meshgrid(x,y,z) ;
f = X.*Y.*Z ;
figure(1)
hold on
for i = 1:N
surf(X(:,:,i),Y(:,:,i),Z(:,:,i),f(:,:,i))
end
  댓글 수: 3
KSSV
KSSV 2017년 3월 28일
You check the ranges of x, y, z for the given function that's the shape. What you expect? Any image available? Attach it.
KSSV
KSSV 2017년 3월 30일
N = 10 ;
x = linspace(0,1,N) ;
y = linspace(0,1,N) ;
z = linspace(0,1,N) ;
[X,Y,Z] = meshgrid(x,y,z) ;
F = X.*Y.*Z ;
isosurface(X,Y,Z,F,0)

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

카테고리

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