If f1(x,y)≤z≤f2(x,y), how to draw the range of z?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
KSSV
am 12 Sep. 2024
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 Kommentare
Shivam
am 12 Sep. 2024
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 Kommentare
Image Analyst
am 12 Sep. 2024
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
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!