Piecewise Function Surface Plot
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Need to plot 2 utility functions on the same surface plot. They should connect seamlessly.
U(x1, x2) = 2*x1 + 2*(x2)^2 [0 <= (x1 + (x2)^2) <= 1]
U(x1, x2) = x1 + (x2)^2 + 2 [1 <= (x1 + (x2)^2) <= 2]
I have no idea how to accomplish this especially with the bounds containing a function, itself
0 Kommentare
Antworten (2)
Torsten
am 25 Okt. 2022
Hint: The function can be defined as
fun = @(x,y) (2*x+2*y^2)*(x+y^2>=0 && x+y^2<=1) + (x+y^2+2)*(x+y^2>1 && x+y^2<=2);
0 Kommentare
Star Strider
am 25 Okt. 2022
They are not seamless because the first surface ends with Z=1 and the second begins with Z=2. Change the constant in the second, and they are seamless.
U = @(x1,x2) (2*x1 + 2*x2.^2) .* (((x1 + x2.^2) >= 0) & ((x1 + x2.^2) <= 1)) + (x1 + x2.^2 + 2) .* (((x1 + x2.^2) >= 1) & ((x1 + x2.^2) <= 2));
x = linspace(-1, 3);
y = linspace(-1, 3);
[X,Y] = ndgrid(x,y);
figure
fsurf(U, [ -2 3 -2 3], 'MeshDensity',75)
U = @(x1,x2) (2*x1 + 2*x2.^2) .* (((x1 + x2.^2) >= 0) & ((x1 + x2.^2) <= 1)) + (x1 + x2.^2 + 1) .* (((x1 + x2.^2) >= 1) & ((x1 + x2.^2) <= 2));
x = linspace(-1, 3);
y = linspace(-1, 3);
[X,Y] = ndgrid(x,y);
figure
fsurf(U, [ -2 3 -2 3], 'MeshDensity',75)
.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


