MATLAB lualways performs a default rotation. If you had, for example, a diagonal coefficient equal to 0 when you tried to execute the usual LU decomposition algorithm, it will not work, since the diagonal coefficients are necessary when executing the Gauss exception to create the upper triangular matrix U, so that you get a division by zero error. To ensure stable decomposition, rotation is required.
, , , , . , , . U, , L , , U.
- , A. , . LU MATLAB lu_nopivot:
function [L, U] = lu_nopivot(A)
n = size(A, 1); % Obtain number of rows (should equal number of columns)
L = eye(n); % Start L off as identity and populate the lower triangular half slowly
for k = 1 : n
% For each row k, access columns from k+1 to the end and divide by
% the diagonal coefficient at A(k ,k)
L(k + 1 : n, k) = A(k + 1 : n, k) / A(k, k);
% For each row k+1 to the end, perform Gaussian elimination
% In the end, A will contain U
for l = k + 1 : n
A(l, :) = A(l, :) - L(l, k) * A(k, :);
end
end
U = A;
end
, 3 x 3:
>> rng(123)
>> A = randi(10, 3, 3)
A =
7 6 10
3 8 7
3 5 5
:
>> [L,U] = lu_nopivot(A)
L =
1.0000 0 0
0.4286 1.0000 0
0.4286 0.4474 1.0000
U =
7.0000 6.0000 10.0000
0 5.4286 2.7143
0 0 -0.5000
L U :
>> L*U
ans =
7 6 10
3 8 7
3 5 5
..., A.