LDU decomposition of a matrix A This subroutine performs LDU decomposition of a given matrix A, where L is a lower triangular matrix, D is a diagonal matrix, and U is an upper triangular matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in), | dimension(:, :) | :: | A | ||
| real(kind=dp), | intent(out), | dimension(size(A, 1), size(A, 1)) | :: | L | ||
| real(kind=dp), | intent(out), | dimension(size(A, 1), size(A, 1)) | :: | D | ||
| real(kind=dp), | intent(out), | dimension(size(A, 1), size(A, 1)) | :: | U |
subroutine LDU_decomposition(A, L, D, U) real(dp), dimension(:, :), intent(in) :: A real(dp), dimension(size(A, 1), size(A, 1)), intent(out) :: L, U, D integer :: i, j, k, N N = size(A, 1) L = 0.d0 D = 0.d0 U = 0.d0 do j = 1, N L(j, j) = 1.d0 U(j, j) = 1.d0 do i = 1, j - 1 U(i, j) = (A(i, j) - & dot_product(L(i, 1:i - 1), U(1:i - 1, j)*[(D(k, k), k=1, i - 1)])) / & D(i, i) end do i = j D(j, j) = A(j, j) - & dot_product(L(j, 1:j - 1), U(1:j - 1, j)*[(D(k, k), k=1, j - 1)]) do i = j + 1, N L(i, j) = (A(i, j) - & dot_product(L(i, 1:j - 1), U(1:j - 1, j)*[(D(k, k), k=1, j - 1)])) / & D(j, j) end do end do end subroutine LDU_decomposition