Plot level curves and projections as a contour
24 次查看(过去 30 天)
显示 更早的评论
I have created a surface plot for the function
and
as follows:
and
as follows:close all
clear all
N1 = 10;
N2 = 10;
x1 = linspace(-1,1,N1);
x2 = linspace(-1,1,N2);
a = -1;
b = 2;
dx2_1 = zeros(N1,N2);
dx2_2 = zeros(N1,N2);
F1 = @(x2,x1,b,a) x1*a*b*(1-2*x2)/(b-1-x2);
F2 = @(x2,x1,b,a) x1*a*b*x2/(b-1+x2);
for i = 1:N1
for j = 1:N2
if a > 0
dx2_1(i,j) = 2*F1((x2(j)-1),(x1(i)-1),b,a);
else
dx2_1(i,j) = 2*F2((x2(j)-1),(x1(i)-1),b,a);
end
end
end
figure(1)
surf(x1,x2,dx2_1)
xlabel('x_2')
ylabel('x_1')
And here's the out put that I got from the above surface plot.

I'm trying to project level curves of this surface onto the
plane and plot them with respect to
and a(by varying a) as a contour/streamlinre plot. Can someone please assist me with the code for this problem?
0 个评论
采纳的回答
Star Strider
2022-5-10
I am not certain what result you want.
N1 = 10;
N2 = 10;
x1 = linspace(-1,1,N1);
x2 = linspace(-1,1,N2);
a = -1;
b = 2;
dx2_1 = zeros(N1,N2);
dx2_2 = zeros(N1,N2);
F1 = @(x2,x1,b,a) x1*a*b*(1-2*x2)/(b-1-x2);
F2 = @(x2,x1,b,a) x1*a*b*x2/(b-1+x2);
for i = 1:N1
for j = 1:N2
if a > 0
dx2_1(i,j) = 2*F1((x2(j)-1),(x1(i)-1),b,a);
else
dx2_1(i,j) = 2*F2((x2(j)-1),(x1(i)-1),b,a);
end
end
end
figure(1)
hsc = surfc(x1,x2,dx2_1);
Levels = hsc(2).LevelList % Get Current Levels
hsc(2).LevelList = [-60:10:90]; % Set Levels As Desired
hold on
contour3(x1,x2,dx2_1, '-r', 'LineWidth',2)
hold off
xlabel('x_2')
ylabel('x_1')
Specifying the contour levels and number of contours are options described in the contour3 documentation. Set the levels for the surfc plot using the 'LevelList' property as outlined here. (Getting the levels first is not necessary. I show that here simply to demonstrrate the approach.)
.
2 个评论
Star Strider
2022-5-13
My pleasure!
I don’t completely understand what you want to do or how you want to vary the plotted surface.
I would just use contour for this, and use the contour ‘c’ output to draw each contour using plot3, with the ‘z’ value being ones(1,k)*a (with ‘k’ being the number of elements in each contour) to draw the different contours at each level. The original surface appears to be relatively straightforward with respect to the contours, with only one contour at a specific level (as opposed to contours within contours and other such problems), so that should be reatively straightforward to do.
.
更多回答(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!




