Help with contour plot
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
LUCA D'AMBROSIO
le 17 Juil 2024
Modifié(e) : Adam Danz
le 17 Juil 2024
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
0 commentaires
Réponse acceptée
Aquatris
le 17 Juil 2024
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
legend()
xlabel('k_a_1_2')
ylabel('k_a_2_1')
grid on
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!