Piecewise Function Surface Plot

19 visualizaciones (últimos 30 días)
Robert Rose
Robert Rose el 25 de Oct. de 2022
Respondida: Star Strider el 25 de Oct. de 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

Respuestas (2)

Torsten
Torsten el 25 de Oct. de 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 el 25 de Oct. de 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)
.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by