You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用简洁命令构造由基矩阵幂次构成的分块矩阵?

Concise Ways to Build Block Matrix of Matrix Powers in MATLAB

Great question! When you need to construct a block matrix B = [A; A²; A³; ...; Aⁿ] from a base matrix A, there are cleaner, more elegant alternatives to explicit for loops. Here are my go-to approaches:

1. One-Liner with arrayfun + cell2mat

While you mentioned arrayfun, you can condense it into a single, readable line without a full loop. This is perfect for small to moderate values of n:

n = 3; % Replace with your desired positive integer
A = [1, 2; -1, 3];
B = cell2mat(arrayfun(@(k) A^k, 1:n, 'UniformOutput', false));

How it works:

  • arrayfun(@(k) A^k, 1:n, 'UniformOutput', false) generates a cell array where each element is A^k for k from 1 to n.
  • cell2mat then vertically stacks all these matrices into your desired block matrix B.

2. Efficient Recursive Approach (Cayley-Hamilton Theorem)

For larger values of n, computing each matrix power individually can be inefficient. Instead, use the Cayley-Hamilton Theorem, which states that any matrix satisfies its own characteristic equation. This lets us express higher powers of A as linear combinations of lower powers, reducing redundant calculations:

n = 5; % Example large n
A = [1, 2; -1, 3];

% Get coefficients of A's characteristic polynomial
char_poly = poly(A);

% Initialize cell array to hold matrix powers
powers = cell(1, n);
powers{1} = A;
if n >= 2, powers{2} = A^2; end

% Recursively compute higher powers using Cayley-Hamilton
for k = 3:n
    % Combine lower powers using the characteristic equation
    powers{k} = -char_poly(1:end-1) * cell2mat(powers(k-1:-1:k-length(char_poly)+1));
end

% Stack into the final block matrix
B = cell2mat(powers);

This method shines when n is large because it avoids recalculating matrix products from scratch for each power.

Quick Note on Element-Wise vs Matrix Powers

Just to clarify: since you mentioned scalar A.^(1:n), remember that A^k is matrix multiplication (what you need here), while A.^k is element-wise exponentiation—make sure you use the correct operator for your use case!

内容的提问来源于stack exchange,提问作者ThomasIsCoding

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:47:49