how to use for loop for iterations in matrices?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Stephen23
on 20 Aug 2021
Edited: Stephen23
on 20 Aug 2021
"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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!