NULAPACK
NUmerical Linear Algebra PACKage
Loading...
Searching...
No Matches
cgedtrf.f
Go to the documentation of this file.
1C ====================================================================
2C N U L A P A C K
3C U U L A P A C K
4C L L L A P A C K
5C A A A A P A C K
6C P P P P P A C K
7C A A A A A A C K
8C C C C C C C C K
9C K K K K K K K K
10C
11C This file is part of NULAPACK - NUmerical Linear Algebra PACKage
12C
13C Copyright (C) 2025 Saud Zahir
14C
15C NULAPACK is free software: you can redistribute it and/or modify
16C it under the terms of the GNU General Public License as published by
17C the Free Software Foundation, either version 3 of the License, or
18C (at your option) any later version.
19C
20C NULAPACK is distributed in the hope that it will be useful,
21C but WITHOUT ANY WARRANTY; without even the implied warranty of
22C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23C GNU General Public License for more details.
24C
25C You should have received a copy of the GNU General Public License
26C along with NULAPACK. If not, see <https://www.gnu.org/licenses/>.
27C
28C ====================================================================
29C CGEDTRF - Doolittle Factorization for A = L * U
30C ====================================================================
31C Description:
32C ------------------------------------------------------------------
33C Computes the LU decomposition of a general N x N matrix A
34C using the Doolittle algorithm. A is stored as a flat row-major
35C array. The lower triangular matrix L (with ones on the diagonal)
36C and the upper triangular matrix U are stored in L and U arrays.
37C
38C ====================================================================
39C Arguments:
40C ------------------------------------------------------------------
41C N : INTEGER -> matrix size (N x N)
42C A(*) : COMPLEX -> flat row-major matrix A
43C L(*) : COMPLEX -> lower triangular matrix L
44C U(*) : COMPLEX -> upper triangular matrix U
45C INFO : INTEGER -> return code:
46C 0 = success
47C <0 = zero diagonal in U detected
48C ====================================================================
49 SUBROUTINE cgedtrf(N, A, L, U, INFO)
50
51C I m p l i c i t T y p e s
52C ------------------------------------------------------------------
53 IMPLICIT NONE
54
55C D u m m y A r g u m e n t s
56C ------------------------------------------------------------------
57 INTEGER :: N, INFO
58 COMPLEX :: A(*), L(*), U(*)
59
60C L o c a l V a r i a b l e s
61C ------------------------------------------------------------------
62 INTEGER :: I, J, K
63 COMPLEX :: SUM
64
65C I n i t i a l i z e
66C ------------------------------------------------------------------
67 info = 0
68 DO i = 1, n * n
69 l(i) = (0.0, 0.0)
70 u(i) = (0.0, 0.0)
71 END DO
72
73C M a i n D e c o m p o s i t i o n L o o p
74C ------------------------------------------------------------------
75 DO i = 1, n
76C U p p e r T r i a n g u l a r
77C --------------------------------------------------------------
78 DO k = i, n
79 sum = (0.0, 0.0)
80 DO j = 1, i - 1
81 sum = sum + l((i-1)*n + j) * u((j-1)*n + k)
82 END DO
83 u((i-1)*n + k) = a((i-1)*n + k) - sum
84 END DO
85
86C L o w e r T r i a n g u l a r
87C --------------------------------------------------------------
88 DO k = i, n
89 IF (i .EQ. k) THEN
90 l((i-1)*n + i) = (1.0, 0.0)
91 ELSE
92 sum = (0.0, 0.0)
93 DO j = 1, i - 1
94 sum = sum + l((k-1)*n + j) * u((j-1)*n + i)
95 END DO
96
97C Check for zero diagonal to avoid division by zero
98 IF (u((i-1)*n + i) .EQ. (0.0, 0.0)) THEN
99 info = -i
100 RETURN
101 END IF
102
103 l((k-1)*n + i) = (a((k-1)*n + i) - sum) / u((i-1)*n + i)
104 END IF
105 END DO
106 END DO
107
108C S u c c e s s f u l e x i t
109C ------------------------------------------------------------------
110 RETURN
111 END
subroutine cgedtrf(n, a, l, u, info)
Definition cgedtrf.f:50