plot 3D fun in x, y and z
4 views (last 30 days)
Show older comments
i want to draw a function f varied in x, y and z such that f = xyz using matlab 2014a
0 Comments
Answers (2)
John BG
on 28 Mar 2017
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
0 Comments
KSSV
on 28 Mar 2017
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 Comments
KSSV
on 28 Mar 2017
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
on 30 Mar 2017
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)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!