If f1(x,y)≤z≤f2(x,y), how to draw the range of z?
5 次查看(过去 30 天)
显示 更早的评论
x=-5:0.1:5;
y=-5:0.1:5;
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
end
end
surf(x,y,z1,"EdgeColor","none")
hold on
surf(x,y,z2,"EdgeColor","none")
If the upper and lower limits of z are described by separate functions, how to plot the range of the z function in the direction of the z-axis instead of two surfaces?
0 个评论
回答(3 个)
KSSV
2024-9-12
x=-5:0.1:5;
y=-5:0.1:5;
[m,n] = meshgrid(x,y) ;
z1 = m.^2+n.^2;
z2 = 3*m.^3+n.^2+1 ;
surf(x,y,z1,"EdgeColor","none")
hold on
surf(x,y,z2,"EdgeColor","none")
0 个评论
Shivam
2024-9-12
As per my understanding, you are given an inequality f1(x,y) <= z <= f2(x,y) describing the upper and lower limit for z on defined arrays x and y and you want to see the region of z satisfiying the inequality given.
In the workaround provided below, the points z1 and z2, corresponding to f1(x,y) and f2(x,y) respectively, are identified where z1 <= z2. The points that satisfy this condition are plotted in different colors using surface plot.
x = -5:0.1:5;
y = -5:0.1:5;
% Create meshgrid for x and y
[m, n] = meshgrid(x, y);
% Calculate z1 and z2
z1 = m.^2 + n.^2;
z2 = 3*m.^3 + n.^2 + 1;
% Logical mask for the region where z1 <= z2
mask = z2 >= z1;
% Set the values of z1 and z2 to NaN where the condition is not met
% This effectively removes these points from the plot
z1(~mask) = NaN;
z2(~mask) = NaN;
% Plot the region where z1 <= z2
figure;
surf(x, y, z2, 'EdgeColor', 'none', 'FaceAlpha', 0.7, 'FaceColor', 'r');
hold on;
surf(x, y, z1, 'EdgeColor', 'none', 'FaceAlpha', 0.7, 'FaceColor', 'b');
% Add labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Region where z1 <= z2');
grid on;
hold off;
The region between red and blue surface is technically the preferred region for z as per the given equality.
I hope it helps.
0 个评论
Image Analyst
2024-9-12
Do you want just the magnitude of the range, without visualizing the starting and stopping points? If so you can just subtract the functions:
x=-5:0.1:5;
y=-5:0.1:5;
for m=1:101
for n=1:101
z1(m,n)=x(m)^2+y(n)^2;
z2(m,n)=3*x(m)^3+y(n)^2+1;
end
end
rangeMagnitude = abs(z1-z2);
imshow(rangeMagnitude, []);
axis('on', 'image')
colorbar
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!