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!