How make create 3D plots using piece wise functions?

12 次查看(过去 30 天)
Hello i'm trying to create a 3d plot using a given pice wise function. Same as figure A . Figure B shows an example I took from the website. I was trying to modify the parameters of piece wise but I was a little confuse with domains. Also sorry for the imcomplete question, I acccidentally hit enter before completing the question. This is the first question I ask in this website. Any feedback would be greatly appreciated.
f1 = @(x,y) erf(x)+cos(y);
fsurf(f1,[-5 0 -5 5])% How do you enter the Z domain?
hold on
f2 = @(x,y) sin(x)+cos(y);
fsurf(f2,[0 5 -5 5])
hold off

回答(2 个)

Star Strider
Star Strider 2021-1-7
编辑:Star Strider 2021-1-7
... rest of your sentence is missing!
Try this:
x = linspace(-5, 5, 50);
y = linspace(0, 10, 50);
[X,Y] = ndgrid(x,y);
Z = @(x,y) x.^2.*((x>= -1) & (x<=3)) + sin(2*pi*y/5).*((y>=-2) & (y<=8));
figure
surf(X, Y, Z(X,Y))
grid on
EDIT — (7 Jan 2021 at 3:54)
This is obviously homework so we give hints rather than solutions.
In that spirit, I suggest that you explore the isosurface function (and its friends).
  1 个评论
fofoplitt
fofoplitt 2021-1-7
编辑:fofoplitt 2021-1-7
This is a indeed homework and I already solved the question. I was just trying to include in the figure in latex doc i'm currently working on and learn how to 3d plots in matlab. I'm not trying to solve the question i just want to draw the figure.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2021-1-7
syms x y
z = piecewise(x < 5 & y < x.^2, sin(x)+sin(y), cos(x.*y));
[X, Y] = ndgrid(linspace(0,10,250));
Z = double(subs(z, {x,y}, {X,Y}));
surf(X, Y, Z, 'edgecolor', 'none')

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by