0

我在我的 MATLAB 代码上使用分析器,以下行占用了代码计算时间的 50%:

firstSide = -1*HessianInverse*(eye(n,n)- ...
currentA'(currentA*HessianInverse*currentA')^-1*currentA*HessianInverse)*currentG;
  • HessianInverse 是一个 nxn 矩阵
  • currentG 是一个 nxn 矩阵
  • currentA 也是一个 nxn 矩阵

进行此计算的最快方法是什么?

4

1 回答 1

2

你可以做两件简单的事情:

  • 计算currentA*HessianInverse一次并存储结果,因为您在两个不同的地方使用相同的矩阵乘法。
  • 替换^-1\运算符,因为后者的速度大约是后者的两倍:

例如

>> A = rand(1000);
>> B = rand(1000);

>> tic; A^-1*B; toc
Elapsed time is 0.592531 seconds.
>> tic; A^-1*B; toc
Elapsed time is 0.578318 seconds.

>> tic; A\B; toc
Elapsed time is 0.275542 seconds.
>> tic; A\B; toc
Elapsed time is 0.262008 seconds.
于 2014-03-26T02:56:49.317 回答