Académique Documents
Professionnel Documents
Culture Documents
'*
*
'* X12 = 0.118877 -0.189941
*
'*
*
'* X13 = 0.514975 -0.822819
*
'*
*
'* X14 = 0.013271 -0.021204
*
'*
*
'* X15 = 0.731170 -1.168252
*
'*
*
'* ------------------------------------------------------------------ *
'* Subroutines used:
*
'* 1000 LUDCMP: LU decomposition of a real square matrix
*
'* 2000 LUBKSB: Solve linear system AX = B, A being the
*
'*
output of LUDCMP.
*
'*
*
'**********************************************************************
DEFINT I-N
DEFDBL A-H, O-Z
CLS :
INPUT
in$ =
ou$ =
PRINT
" Data file name (without .dat): ", nom$
nom$ + ".dat"
nom$ + ".lst"
N1 = N + 1
N2 = N1 * N1
DIM AR(N2), AI(N2), BR(N1), BI(N1), temp(N1, 2), INDX(N1)
'-----------------------------------------------------------------'NOTA: Complex Matrix A of size N+1 x N+1 is stored in txo vectors,
'
line by. AR one for real part and AI for imaginary part.
'
The element (i,j) of the matrix is at location i(n+1) + j in
'
the corresponding vector. The access is faster.
'-----------------------------------------------------------------PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
#2,
#2,
#2,
#2,
#2,
#2,
"--------------------------------------------------"
"
COMPLEX LINEAR SYSTEM TO BE SOLVED:"
"--------------------------------------------------"
" N="; N
FOR I = 1 TO N
FOR J = 1 TO N + 1
INPUT #1, temp(J, 1), temp(J, 2)'read a line
NEXT J
FOR J = 1 TO N
AR(I * (N + 1) + J) = temp(J, 1)
AI(I * (N + 1) + J) = temp(J, 2)
NEXT J
BR(I) = temp(N + 1, 1)
BI(I) = temp(N + 1, 2)
FOR J = 1 TO N + 1
PRINT #2, USING " ###.## ###.##"; temp(J, 1); temp(J, 2);
NEXT J
PRINT #2,
NEXT I
CLOSE #1
GOSUB 1000 'LUDCMP(A,n,INDX,D,CODE)
IF CODE = 0 THEN GOSUB 2000
'LUBKSB(A,n,INDX,B);
IF CODE = 1 THEN
PRINT #2, " The system matrix is singular !"
ELSE
PRINT #2,
PRINT #2, " System solution:"
PRINT #2,
FOR I = 1 TO N
PRINT #2, USING " X## = ##.###### ##.######"; I; BR(I); BI(I)
PRINT #2,
NEXT I
END IF
PRINT #2, "--------------------------------------------------"
PRINT #2, " End of file "; ou$
CLOSE #2
PRINT
PRINT " Results in file "; ou$
PRINT
END 'of main program
'***************************************************************
'* Given an N x N matrix A, this routine replaces it by the LU *
'* decomposition of a rowwise permutation of itself. A and N *
'* are input. INDX is an output vector which records the row *
'* permutation effected by the partial pivoting; D is output *
'* as -1 or 1, depending on whether the number of row inter- *
'* changes was even or odd, respectively. This routine is used *
'* in combination with LUBKSB to solve linear equations or to *
'* invert a matrix. Return code is 1, if matrix is singular. *
'***************************************************************
1000 'SUBROUTINE LUDCMP FOR COMPLEX MATRIX
NMAX = 100: TINY = 2.2E-16
DIM VV(N, 2), AMAX(2), SUM(2), DUM(2), TMP(2), TMP1(2)
D = 1: CODE = 0
FOR I = 1 TO N
AMAX(1) = 0#: AMAX(2) = 0#
FOR J = 1 TO N
IF CABS(AR(I * N1 + J), AI(I * N1 + J)) > CABS(AMAX(1), AMAX(2)) THEN
AMAX(1) = AR(I * N1 + J)
AMAX(2) = AI(I * N1 + J)
END IF
NEXT J
IF CABS(AMAX(1), AMAX(2)) < TINY THEN
CODE = 1
RETURN
END IF
'
AI(J * N1 + J) = 0#
END IF
IF J <> N THEN
DUM = 1# / A(J * N1 + J)
TMP(1) = 1#: TMP(2) = 0#
TMP1(1) = AR(J * N1 + J): TMP1(2) = AI(J * N1 + J)
CDIV TMP(), TMP1(), DUM()
FOR I = J + 1 TO N
'
A(I * N1 + J) = A(I * N1 + J) * DUM
TMP(1) = AR(I * N1 + J): TMP(2) = AI(I * N1 + J)
CMUL TMP(), DUM(), TMP1()
AR(I * N1 + J) = TMP1(1)
AI(I * N1 + J) = TMP1(2)
NEXT I
END IF
NEXT J 'j loop
'