how to use for loop for iterations in matrices?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, how can I use for loop for these operations?
let x1= rand(5,3);
and x2= rand(5,3);
also, A1=x2*pinv(x1);
Now, I want to use A1 and x2 to get X3, i.e
x3=A1*x2;
and then,
A2=x3*pinv(x2);
x4=A2*x3; and so on.
I want to get the final X matrix after 10 iterations using for loop. i.e x10.
Thank you
댓글 수: 0
채택된 답변
Stephen23
2021년 8월 20일
편집: Stephen23
2021년 8월 20일
"how to use for loop for iterations in matrices?"
Do NOT number the variable names, unless you want to force yourself into writing slow, complex, inefficient code.
Use a cell array instead, with indexing, e.g.:
C = {rand(5,3),rand(5,3)};
for k = 3:10
A = C{k-1} * pinv(C{k-2});
C{k} = A * C{k-1};
end
M = C{10}
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!