How to construct a cell array containing a power series of a matrix

2 views (last 30 days)
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.

Answers (1)

Bill Tubbs
Bill Tubbs on 28 May 2021
Edited: Bill Tubbs on 28 May 2021
Here is a solution using cellfun:
results = cellfun(@(i) A^i, num2cell(1:n), 'UniformOutput', false)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!