Matrix power vs for loop
Show older comments
Hi.
I have to iterate a linear system of the type x(k+1) = Ax(k), with x being a vector of 1024 elements. I only care about the last vector obtained, this is, x(endtime).
What would be faster?
x0 =rand(1024,1)
x = x0;
for i = 1:endtime
x = A*x
end
or
x = (A^endtime) * x0
Thanks.
Accepted Answer
More Answers (1)
James Tursa
on 26 Jun 2023
0 votes
Note that the A^endtime method is probably going to be more accurate as endtime gets larger. The loop method can have a tendancy to build up errors.
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!