2x2 matrix that changes with iteration of for loop

3 vues (au cours des 30 derniers jours)
David Fariyike
David Fariyike le 27 Juin 2020
Commenté : David Fariyike le 27 Juin 2020
Hello,
I am trying to define a 2x2 matrix that changes with each increment of a for loop. This is what I currently have but it only gives me 1 2x2 matrix.
for ii=1:length(tt),
J={-L1*s1(ii)-L2*s12(ii) -L2*s12(ii);
L1*c1(ii)+L2*c12(ii) L2*c12(ii)};
end
I am not defining everything for simplicity purposes. But s1(ii), s12(ii), c1(ii), and c12(ii) are all solved in the for loop and each a 1x5001 matrix. The L1 and L2 are constants. I am trying to define J as a 2x2 matrix 5001 times.

Réponse acceptée

madhan ravi
madhan ravi le 27 Juin 2020
s1 = reshape(s1,1,1,[]);
s12 = reshape(s12,1,1,[]);
c1 = reshape(c1,1,1,[]);
c12 = reshape(c12,1,1,[]);
J = [-L1*s1-L2*s12, -L2*s12;
L1*c1+L2*c12, L2*c12]
  1 commentaire
David Fariyike
David Fariyike le 27 Juin 2020
This works for me but sorry one last thing. I would like to take the inverse of the J matrix and multiply by a 2x5001 matrix.
Jinv=J.^-1;
thetadot=Jinv.*X_dot
I tried to do the reshape technique to make it a 2x1x5001
X_dot = reshape(X_dot,2,1,[]);
but I am returning 2x2 matrices instead of 2x1. A (2x2) multiplied by a (2x1) should return a (2x1).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by