Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do you plot with a double for loop? I want to plot the last value of U with respect to c_2 continuously, having a nice curve.

1 回表示 (過去 30 日間)
Alex M
Alex M 2017 年 11 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
%%Parameters
format short
% Constants
rho=1.225;
U=170;
s=1;
c=0.5;
c_2=1;
b=0.5*c;
m=5;
I_CG=0.05;
k1=10000;
k2=10000;
k3=10000;
m_p=0.5;
% x_p=(0:0.01:c);
zero=[0 0; 0 0];
% Variables
x_g=0.5*c;
x_1=0.1*c;
x_ac=0.25*c;
x_3=0.7*c;
q=0.5*rho*u^2;
u_final = zeros(1, numel(0:0.1:20));
counter = 1;
for c_2=[0:0.1:20]
for u = [0:1:75]
M=[ m -m*(x_ac - x_g); -m*(x_ac - x_g) I_CG + m*(x_ac - x_g)^2 ];
E=[k1 + k2 + k3 k1*(x_1 - x_ac) + k3*(x_3 - x_ac); k1*(x_1 - x_ac) + k3*(x_3 - x_ac) k1*(x_1 - x_ac)^2 + k3*(x_3 - x_ac)^2];
B=[1+c_2/(pi*s*c*rho) c/2; 0 c^2/16];
Bbar=pi*s*c*rho*[B];
K=[0 1; 0 0];
Kbar=pi*s*c*rho*[K];
A=[[M] u*[Bbar];[zero] [M]];
C=[[zero] [E]+u^2*[Kbar] ; -[M] [zero] ];
c_2;
u;
lambda=eig(C,-A);
if any(lambda>0)
u_final(1, counter) = u;
counter = counter + 1;
break
end
end
end
figure(4)
set(gcf,'color','w');
plot (0:0.1:20,u_final,'r')
xlabel ('Dampening Magnitude c_2');
ylabel ('Speed Limit [m/s]');
axis([0 20 0 80 ])
grid on

回答 (1 件)

KSSV
KSSV 2017 年 11 月 21 日
%%Parameters
format short
% Constants
rho=1.225;
U=170;
s=1;
c=0.5;
c_2=1;
b=0.5*c;
m=5;
I_CG=0.05;
k1=10000;
k2=10000;
k3=10000;
m_p=0.5;
% x_p=(0:0.01:c);
zero=[0 0; 0 0];
% Variables
x_g=0.5*c;
x_1=0.1*c;
x_ac=0.25*c;
x_3=0.7*c;
% q=0.5*rho*u^2;
u_final = zeros(1, numel(0:0.1:20));
counter = 1;
figure(4)
hold on
set(gcf,'color','w');
xlabel ('Dampening Magnitude c_2');
ylabel ('Speed Limit [m/s]');
axis([0 20 0 80 ])
grid on
for c_2=[0:0.1:20]
for u = [0:1:75]
M=[ m -m*(x_ac - x_g); -m*(x_ac - x_g) I_CG + m*(x_ac - x_g)^2 ];
E=[k1 + k2 + k3 k1*(x_1 - x_ac) + k3*(x_3 - x_ac); k1*(x_1 - x_ac) + k3*(x_3 - x_ac) k1*(x_1 - x_ac)^2 + k3*(x_3 - x_ac)^2];
B=[1+c_2/(pi*s*c*rho) c/2; 0 c^2/16];
Bbar=pi*s*c*rho*[B];
K=[0 1; 0 0];
Kbar=pi*s*c*rho*[K];
A=[[M] u*[Bbar];[zero] [M]];
C=[[zero] [E]+u^2*[Kbar] ; -[M] [zero] ];
c_2;
u;
lambda=eig(C,-A);
if any(lambda>0)
u_final(1, counter) = u;
counter = counter + 1;
break
end
end
plot (0:0.1:20,u_final,'r')
end

Community Treasure Hunt

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

Start Hunting!

Translated by