Effacer les filtres
Effacer les filtres

How make create 3D plots using piece wise functions?

17 vues (au cours des 30 derniers jours)
fofoplitt
fofoplitt le 7 Jan 2021
Modifié(e) : fofoplitt le 7 Jan 2021
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

Réponses (2)

Star Strider
Star Strider le 7 Jan 2021
Modifié(e) : Star Strider le 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.
In that spirit, I suggest that you explore the isosurface function (and its friends).
  1 commentaire
fofoplitt
fofoplitt le 7 Jan 2021
Modifié(e) : fofoplitt le 7 Jan 2021
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.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 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')

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by