Matrix power vs for loop
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
James Tursa
2023-6-26
0 个投票
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.
类别
在 帮助中心 和 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!