How to construct a cell array containing a power series of a matrix
2 次查看(过去 30 天)
显示 更早的评论
I want to compute the following power series of a square matrix A (as a preliminary step to constructing a larger matrix using these results):
results = {A, A^2, A^3, ... , A^n}
where n is variable.
Ideally, I want the result to be a cell array so I can reference them later using an integer index, but a block matrix would also be usable.
Obviously, if A were a scalar this would be quite easy:
>> A = 0.8;
>> results = mat2cell(A.^(1:n),1,ones(1,n))
results =
1×4 cell array
{[0.8000]} {[0.6400]} {[0.5120]} {[0.4096]}
It can be done with a for loop:
results = cell(1,n);
X = A;
for i=1:n
results(i) = {X};
X = X*A;
end
and I will add another solution below, but I suspect there is a simpler and/or more efficient way.
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!