필터 지우기
필터 지우기

Help with contour plot

조회 수: 1 (최근 30일)
LUCA D'AMBROSIO
LUCA D'AMBROSIO 2024년 7월 17일
편집: Adam Danz 2024년 7월 17일
Hello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = ['r','g','b','c','k'];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J - M*a1*a2);
D = k1(q)*k2 - X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = ['k_1 = ', num2str(k1(q))];
contour(X, Y, Z, v, 'LineWidth', 1.2, 'LineColor', clr(q), 'DisplayName', LegendsStrings{q});
hold on
end
legend()
xlabel('k_a_1_2')
ylabel('k_a_2_1')
grid on

채택된 답변

Aquatris
Aquatris 2024년 7월 17일
You actually do have 5 lines but they are on top of each other thats why you do not see them. So your Z matrix for k1(1) and k1(2) are the same. Also Z matrix for k1(3) to k1(5) are the same.
So here is you code for 4 points instead of 101 to visaulize easily. You can also click and delete the lines in your plot to see the underlying lines:
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 4;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = ['r','g','b','c','k'];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J - M*a1*a2);
D = k1(q)*k2 - X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
fprintf('Z for k1 = %.2f is\n',k1(q))
disp(Z)
LegendsStrings{q} = ['k_1 = ', num2str(k1(q))];
contour(X, Y, Z, v, 'LineWidth', 1.2, 'LineColor', clr(q), 'DisplayName', LegendsStrings{q});
hold on
end
Z for k1 = -100000.00 is
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Warning: Contour not rendered for constant ZData
Z for k1 = -50000.00 is
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Warning: Contour not rendered for constant ZData
Z for k1 = 0.00 is
1.0e+09 * -0.0000 -0.0000 0.8333 2.5000 -0.0000 -0.0000 0.2778 -0.0000 0.8333 0.2778 -0.0000 -0.0000 2.5000 -0.0000 -0.0000 -0.0000
Z for k1 = 50000.00 is
1.0e+09 * -0.0000 -0.0000 0.8333 2.5000 -0.0000 -0.0000 0.2778 0.8333 0.8333 0.2778 -0.0000 -0.0000 2.5000 0.8333 -0.0000 -0.0000
Z for k1 = 100000.00 is
1.0e+09 * -0.0000 -0.0000 0.8333 2.5000 -0.0000 -0.0000 0.2778 0.8333 0.8333 0.2778 -0.0000 -0.0000 2.5000 0.8333 -0.0000 -0.0000
legend()
xlabel('k_a_1_2')
ylabel('k_a_2_1')
grid on
  댓글 수: 1
LUCA D'AMBROSIO
LUCA D'AMBROSIO 2024년 7월 17일
thank you, i notice it now

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by