2x2 matrix that changes with iteration of for loop

3 visualizaciones (últimos 30 días)
David Fariyike
David Fariyike el 27 de Jun. de 2020
Comentada: David Fariyike el 27 de Jun. de 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.

Respuesta aceptada

madhan ravi
madhan ravi el 27 de Jun. de 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 comentario
David Fariyike
David Fariyike el 27 de Jun. de 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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by