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
0 个评论
回答(2 个)
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.
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')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!