我在我的MATLAB代码上使用了探查器,以下行占用了代码计算时间的50%:
firstSide = -1*HessianInverse*(eye(n,n)- ...
currentA'(currentA*HessianInverse*currentA')^-1*currentA*HessianInverse)*currentG;
进行此计算的最快方法是什么?
答案 0 :(得分: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.