2x2 matrix that changes with iteration of for loop

3 次查看(过去 30 天)
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.

采纳的回答

madhan ravi
madhan ravi 2020-6-27
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 个评论
David Fariyike
David Fariyike 2020-6-27
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).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by