Plot level curves and projections as a contour

87 visualizaciones (últimos 30 días)
UserCJ
UserCJ el 10 de Mayo de 2022
Comentada: Star Strider el 13 de Mayo de 2022
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?

Respuesta aceptada

Star Strider
Star Strider el 10 de Mayo de 2022
I am not certain what result you want.
The contour3 function or surfc could be an option —
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
Levels = 1×8
-60.0000 -40.0000 -20.0000 0 20.0000 40.0000 60.0000 80.0000
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 comentarios
UserCJ
UserCJ el 13 de Mayo de 2022
@Star Strider Thanks for your answer.
Here's what I need to do:
For a given value of a and b in , we project the surface contour C onto the plane. Then we vary a and plot all the contours in plane. My guess is that's goint to be a 4D plot, because our axes are and . So it will look like the plot below:
I'm not sure whether this can be interpreted with streamlines, but I'm trying to do it in either way. It would be great if you can provide me some MATLAB suggestions for this.
Thanks for your help!
Star Strider
Star Strider el 13 de Mayo de 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.
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by