MATLAB:许多矩阵求逆速度更快

时间:2019-06-21 12:33:23

标签: matlab matrix-inverse

假设我有一个多维数组X,其大小为A x A xB。 在这里,我假设B等于100或1000,而A很小,例如4或8。 然后,我要计算Y,它的大小与X的大小相同,并且 Y [:,:,b] = inv(X [:,:b]), 更快 ,比我使用for循环快。 例如,在Python中,Numpy包提供了numpy.linalg.inv(),它可以比幼稚的for循环更快地计算逆矩阵(当然,这是由于Python中for循环的速度较慢)。

A = 4;
B = 1000;
X = rand(A, A, B);
Y = zeros(A, A, B);
for b = 1:B
    Y(:,:,b) = inv(X(:,:,b));
end

Z = ...             % somehow I want get this faster

sum(abs(Y(:)-Z(:))) % so that this is small enough

0 个答案:

没有答案