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

조회 수: 2 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by