Plot a function of three variable

530 views (last 30 days)
Md Borhan Mia
Md Borhan Mia on 16 Jan 2019
Edited: VBBV on 14 Oct 2021
Hey, I want to plot a function of three variables. Consider that I have a function like f(x,y,z)=x^2+y^2+z^2-3xyz, I want a surface plot of this function. How can I do that? Thanks!

Answers (2)

KSSV
KSSV on 16 Jan 2019
f = @(x,y,z) x.^2+y.^2+z.^2-3*x.*y.*z ;
x = linspace(-1,1) ;
y = linspace(-1,1) ;
z = linspace(-1,1) ;
[X,Y,Z] = ndgrid(x,y,z) ;
F =f(X,Y,Z) ;
figure
hold on
for i = 1:100
surf(X(:,:,i),Y(:,:,i),Z(:,:,i),F(:,:,i)) ;
end
  2 Comments
Shubham
Shubham on 17 Nov 2020
syms X Y Z
f = @(x,y,z) x^2 + y^2 + z^2;
surff = f(X,Y,Z);
fimplicit3(surff)

Sign in to comment.


VBBV
VBBV on 14 Oct 2021
Edited: VBBV on 14 Oct 2021
f = @(x,y,z) x.^2+y.^2+z.^2-3*x.*y.*z ;
x = linspace(-1,1) ;
y = linspace(-1,1) ;
z = linspace(-1,1) ;
[X,Y,Z] = ndgrid(x,y,z) ;
F =f(X,Y,Z) ;
figure
hold on
for i = 1:100
surf(X(:,:,i),Y(:,:,i),Z(:,:,i),F(:,:,i)) ;
end
axis([-3 3 -3 3]);grid minor
view(3);
shading interp
Use view function to view the 3Dsurface plot

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!