Piecewise Function Surface Plot
19 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Torsten
2022-10-25
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 个评论
Star Strider
2022-10-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


