Solve a system of linear equations with complex coefficients.
Loading LOADSUB ALL FROM "CSOLVE.HTS"
or LOADSUB FROM "MATHLIB.HTS"
or LOADSUB Csolve FROM "MATHLIB.HTS"
Usage COMPLEX A(*),B(*)
CALL Csolve(A(*),B(*))
Description
Csolvefinds the solution to the system of linear equations represented byAandBand returns the solution inB.Amust be square, that is, it must have the same number of rows as columns.Bmust have the same number of rows asAand usually is a one-dimensional array (a vector). If A represents the matrix whose entries are stored inAand b represents the vector whose entries are stored inB,Csolvefinds the solution vector, z, for the matrix equation
Az = b
and returns the solution inB, replacing the former contents ofB. The contents of the arrayAare also destroyed byCsolve.
The arrayBmay be two-dimensional. In this case, afterCsolveexecutes, each column inBcontains the solution vector for the case when the input values in that column were used as b in the above equation.
Csolveis equivalent to the BASIC lines
MAT Temp=INV(A)
MAT Z=Temp*B
MAT B=Z
except that the arraysTempandZare not needed; the intermediate results overwrite some of the elements ofA.Csolveis faster than the above BASIC fragment, because the matrix inversion is not needed.
Errors
Csolvecauses an HTBasic error if its arguments are not both of type COMPLEX, ifAis not square orBdoesn't have the same number of rows asA, or ifAis singular.