Piecewise Function Surface Plot

19 Ansichten (letzte 30 Tage)
Robert Rose
Robert Rose am 25 Okt. 2022
Beantwortet: Star Strider am 25 Okt. 2022
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

Antworten (2)

Torsten
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);

Star Strider
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.
This is a bit easier to see with fsurf
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)
.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by