How make create 3D plots using piece wise functions?
10 views (last 30 days)
Show older comments
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/480863/image.png)
0 Comments
Answers (2)
Star Strider
on 7 Jan 2021
Edited: Star Strider
on 7 Jan 2021
... 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.
Walter Roberson
on 7 Jan 2021
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')
0 Comments
See Also
Categories
Find more on Get Started with MATLAB 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!