How to store the results of a loop in matlab.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Actually, I need to solve consecutive eigen value problems which are time dependent; accordingly, I want to extract eigen value of each time step using a ''for loop'' in matlab; the point is, however, that results of each loop is needed to be a components of a vector associated with the specific time step; in other words, I want to write a loop for t=0:1:20 that in each loop, matlab calculate the associated eigen value and put it in the vector as a component of it. so at the end of the day we are supposed to have a vector of eigen values associated with vector of time. please find matlab code here, but when I run the code I encounter with the alarm which is showing ''Array indices must be positive integers or logical values'' and I cannot find a vector of eigenvalues in the workspace as a variable.
A = zeros(1,19);
for t = 0:1:19
m(t) = [1.0, 0.89*sin(0.17*t); 0, 120.0]
k(t) = [760, 0; -2.9*sin(0.19*t), 400]
c(t) = [0.44, 0; -0.96*sin(0.17*t), 140 ]
mk = -inv(m(t))*k(t)
mc = -inv(m(t))*c(t)
B(t) = [zeros(2), eye(2); mk(t), mc(t)]
C(t) = real(sqrt(eig(B(t))))
A(t) =C(1)
end
1 commentaire
Réponses (1)
Matt J
le 2 Déc 2022
Modifié(e) : Matt J
le 2 Déc 2022
[B,C,m,k,c]= deal(cell(1,20));
A=nan(1,20);
for t = 1:20
z=t-1;
m{t}= [1.0, 0.89*sin(0.17*z); 0, 120.0];
k{t} = [760, 0; -2.9*sin(0.19*z), 400] ;
c{t} = [0.44, 0; -0.96*sin(0.17*z), 140 ];
mk = -m{t}\k{t};
mc = -m{t}\c{t};
B{t} = [zeros(2), eye(2); mk, mc];
C{t} = real(sqrt(eig(B{t})));
A(t) =C{t}(1);
end
A
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Algebra 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!