performance - Matlab 中更快的矩阵递归

标签 performance matlab recursion matrix

n x n 矩阵 Y_t 的矩阵递归如下所示:

Y_{t} = A + \sum_{i=1}^{p} B_{i} * Y_{t-i}

给出了A和B。

这是我的尝试,但运行缓慢:

Y = zeros(n,n,T); %Going to fill the 3rd dimension for Y_t, t=1:T
Y(:,:,1:p) = initializingY

for t=(p+1):T
    Y(:,:,t) = A;
    for i=1:p
        Y(:,:,t) = Y(:,:,t) + B(:,:,i)*Y(:,:,t-i);
    end
end

你能想出更有效的方法吗?

最佳答案

你可以用matrix-multiplication终止内部循环经过一些reshaping & permuting,像这样-

Y = zeros(n,n,T);
%// Y(:,:,1:p) = initializingY
for t=(p+1):T
    Br = reshape(B(:,:,1:p),n,[]);
    Yr = reshape(permute(Y(:,:,t-(1:p)),[1 3 2]),[],n);
    Y(:,:,t) = A + Br*Yr;
end

关于performance - Matlab 中更快的矩阵递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33673273/

相关文章:

python - 计算 Vandermonde 矩阵的有效方法

matlab - 隐藏 Matlab 图形窗口的最大化/最小化和关闭按钮

.net - 低速网络,断线风险高

matlab - 在 Matlab 中,如何使用色度子采样来缩小 4 :4:4 image to 4:1:1 when the image is in YCbCr?

C++ 对象的 C++ vector 到 mex 中的 mxArray

Java - 使用递归的深度克隆数组;未知类型和未知深度

javascript - 递归 JS 函数列出 Hx HTML 标签?

algorithm - 这个算法的 Big-O 和运行时间,如何将其转换为迭代算法

html - 将同一个 Div 的一个放在另一个的后面?

performance - Haskell 中具有 rank-2 多态性的令人费解的性能/输出行为