If f1(x,y)≤z≤f2(x,y), how to draw the range of z?
조회 수: 6 (최근 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!