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

3 ビュー (過去 30 日間)
Bill Tubbs
Bill Tubbs 2021 年 5 月 28 日
編集済み: Bill Tubbs 2021 年 5 月 28 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by