rref与LU解决复杂性

时间:2016-09-01 03:35:14

标签: matlab

今天我通过比较两种基本方法的运行时间来解决Ax = b,其中A是正方形而b是列向量,我正在进行'健全性测试':

    A = rand(1000,1000); b = rand(1000,1); Xmat = zeros(1000,1001);
    tic; [L,U] = lu(A);  x = U\(L\y); toc;
    tic; Xmat = rref([A b]); toc;

输出:

    Elapsed time is 0.018528 seconds.
    Elapsed time is 10.215791 seconds.

我发现这种差异令人惊讶,因为对于随机,密集的矩阵,我期望LU步骤与高斯消除一样昂贵(这反过来看起来与寻找增强矩阵的减少的梯形形式一样昂贵,除非我错过了什么)。我没想到LU只对一个矢量b做得很好。对于更适度的线性系统(例如100x100矩阵),这种差异也会持续存在。这里发生了什么事?

1 个答案:

答案 0 :(得分:0)

Gaussian elimination is not how LU is computed. Also LU is a "primitive" decomposition that is highly optimized in the Fortran LAPACK over decades. rref is computed at the matlab level by row swapping and pivoting. Moreover, rref checks the matrix entries and converts the entries into fractional representations if possible via rats function. That gives a huge overhead for rref. Because the only possible use case for rref is either educational or demonstration purposes. It is numerically not as reliable as LU decomposition.

That's the speed difference you are seeing.

Don't use rref if you are doing serious computations.