How make create 3D plots using piece wise functions?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Star Strider
el 7 de En. de 2021
Editada: Star Strider
el 7 de En. de 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.
1 comentario
Walter Roberson
el 7 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!