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.

回答(1 个)

Bill Tubbs
Bill Tubbs 2021-5-28
编辑:Bill Tubbs 2021-5-28
Here is a solution using cellfun:
results = cellfun(@(i) A^i, num2cell(1:n), 'UniformOutput', false)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by