Plot level curves and projections as a contour
74 views (last 30 days)
Show older comments
I have created a surface plot for the function 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 Comments
Accepted Answer
Star Strider
on 10 May 2022
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 Comments
Star Strider
on 13 May 2022
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.
.
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!