package Jampack; /** Solve solves linear systems of the form
* A*X = B * AH*X = B * X*A = B * X*AH = Bwhere A is a nonsingular Zmat, B is a Zmat, and '^H' denotes the conjugate transpose. Appropriate action is taken for Zmats that are Zltmats, Zutmats, and Zpsdmats. If a decomposition is computed and the History parameter is set, then the decomposition is saved for reuse.
Comments: For triangular matrices only the systems AX=B
and A^HX=B are solved by hard code, the other two being
solved by wizardry involving transposed systems. This
requires the generation of new Zmats of the same size
as B, which is inefficient if B is, say, square. Later
these methods will be implemented with hard code.
@version Pre-alpha
@author G. W. Stewart
*/
public class Solve{
/**
Solves LX = B, where L is a Zltmat and B is a Zmat.
@param L The matrix of the sysem
@param B The right-hand side
@return L-1B
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Thrown for singular L.
*/
public static Zmat aib(Zltmat L, Zmat B)
throws JampackException{
int i, j, k;
Z x = new Z();
L.getProperties();
B.getProperties();
if (L.nr != L.nc)
throw new JampackException
("Rectangular matrix.");
if (L.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
Zmat X = new Zmat(B);
for (i=0; i
Thrown for singular L.
*/
public static Zmat ahib(Zltmat L, Zmat B)
throws JampackException{
int i, j, k;
Z x = new Z();
L.getProperties();
B.getProperties();
if (L.nr != L.nc)
throw new JampackException
("Rectangular matrix.");
if (L.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
Zmat X = new Zmat(B);
for (i=L.nr-1; i>=0; i--){
if (L.re[i][i] == 0.0 && L.im[i][i] == 0.0)
throw new JampackException
("Zero diagonal in solving triangular system");
for (j=0; j
Passed from below.
*/
public static Zmat bai(Zmat B, Zltmat L)
throws JampackException{
int i, j, k;
Z x = new Z();
L.getProperties();
B.getProperties();
if (L.nr != L.nc)
throw new JampackException
("Rectangular matrix.");
if (L.nr != B.nc)
throw new JampackException
("Inconsistent dimensions.");
return H.o(Solve.ahib(L, H.o(B)));
}
/**
Solves XLH = B, where L is a Zltmat and B is a Zmat.
@param B The right-hand side
@param L The matrix of the system
@return BL-H
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat bahi(Zmat B, Zltmat L)
throws JampackException{
int i, j, k;
Z x = new Z();
L.getProperties();
B.getProperties();
if (L.nr != L.nc)
throw new JampackException
("Rectangular matrix.");
if (L.nc != B.nc)
throw new JampackException
("Inconsistent dimensions.");
return H.o(Solve.aib(L, H.o(B)));
}
/**
Solves UX = B, where U is a Zutmat and B is a Zmat.
@param U The matrix of the system
@param B The right-hand side
@return U-1B
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Thrown for singular U.
*/
public static Zmat aib(Zutmat U, Zmat B)
throws JampackException{
int i, j, k;
Z x = new Z();
U.getProperties();
B.getProperties();
if (U.nr != U.nc)
throw new JampackException
("Rectangular matrix.");
if (U.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
Zmat X = new Zmat(B);
for (i=U.nr-1; i>=0; i--)
for (j=0; j
Thrown for singular U.
*/
public static Zmat ahib(Zutmat U, Zmat B)
throws JampackException{
int i, j, k;
Z x = new Z();
U.getProperties();
B.getProperties();
if (U.nr != U.nc)
throw new JampackException
("Rectangular matrix.");
if (U.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
Zmat X = new Zmat(B);
for (i=0; i
Passed from below.
*/
public static Zmat bai(Zmat B, Zutmat U)
throws JampackException{
int i, j, k;
Z x = new Z();
U.getProperties();
B.getProperties();
if (U.nr != U.nc)
throw new JampackException
("Rectangular matrix.");
if (U.nr != B.nc)
throw new JampackException
("Inconsistent dimensions.");
return H.o(Solve.ahib(U, H.o(B)));
}
/**
Solves XUH = B, where U is a Zutmat and B is a Zmat.
@param B The right-hand side
@param U The matrix of the system
@return BU-H
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat bahi(Zmat B, Zutmat U)
throws JampackException{
int i, j, k;
Z x = new Z();
U.getProperties();
B.getProperties();
if (U.nr != U.nc)
throw new JampackException
("Rectangular matrix.");
if (U.nc != B.nc)
throw new JampackException
("Inconsistent dimensions.");
return H.o(Solve.aib(U, H.o(B)));
}
/**
Solves AX = B, where A is a Zmat and B is a Zmat.
@param A The matrix of the sysem
@param B The right-hand side
@return A-1B
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat aib(Zmat A, Zmat B)
throws JampackException{
Zludpp LU;
A.getProperties();
B.getProperties();
if (A.nr != A.nc)
throw new JampackException
("Rectangular matrix.");
if (A.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
if (Parameters.History){
A.clean();
if (A.LU == null)
A.LU = new Zludpp(A);
LU = A.LU;
}
else
LU = new Zludpp(A);
Zmat X = new Zmat(B);
Pivot.row(X, LU.pvt);
return Solve.aib(LU.U, Solve.aib(LU.L, X));
}
/**
Solve AHX = B, where A is a Zmat and B is a Zmat.
@param A The matrix of the sysem
@param B The right-hand side
@return A-HB
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat ahib(Zmat A, Zmat B)
throws JampackException{
Zludpp LU;
A.getProperties();
B.getProperties();
if (A.nr != A.nc)
throw new JampackException
("Rectangular matrix.");
if (A.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
if (Parameters.History){
A.clean();
if (A.LU == null)
A.LU = new Zludpp(A);
LU = A.LU;
}
else
LU = new Zludpp(A);
return Pivot.rowi(Solve.ahib(LU.L, Solve.ahib(LU.U, B)), LU.pvt);
}
/**
Solve XA = B, where A is a Zmat and B is a Zmat.
@param B The right-hand side
@param A The matrix of the sysem
@return BA-1
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat bai(Zmat B, Zmat A)
throws JampackException{
Zludpp LU;
A.getProperties();
B.getProperties();
if (A.nr != A.nc)
throw new JampackException
("Rectangular matrix.");
if (A.nr != B.nc)
throw new JampackException
("Inconsistent dimensions.");
if (Parameters.History){
A.clean();
if (A.LU == null)
A.LU = new Zludpp(A);
LU = A.LU;
}
else
LU = new Zludpp(A);
return H.o(Solve.ahib(A, H.o(B)));
}
/**
Solve XA^H = B, where A is a Zmat and B is a Zmat.
@param B The right-hand side
@param A The matrix of the sysem
@return BA-H
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat bahi(Zmat B, Zmat A)
throws JampackException{
Zludpp LU;
A.getProperties();
B.getProperties();
if (A.nr != A.nc)
throw new JampackException
("Rectangular matrix.");
if (A.nr != B.nc)
throw new JampackException
("Inconsistent dimensions.");
if (Parameters.History){
A.clean();
if (A.LU == null)
A.LU = new Zludpp(A);
LU = A.LU;
}
else
LU = new Zludpp(A);
return H.o(Solve.aib(A, H.o(B)));
}
/**
Solves AX = B, where A is a Zpsdmat and B is a Zmat.
@param A The matrix of the sysem
@param B The right-hand side
@return A-1B
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat aib(Zpsdmat A, Zmat B)
throws JampackException{
Zchol CHOL;
A.getProperties();
B.getProperties();
if (A.nr != A.nc)
throw new JampackException
("Rectangular matrix.");
if (A.nr != B.nr)
throw new JampackException
("Inconsistent dimensions.");
if (Parameters.History){
A.clean();
if (A.CHOL == null)
A.CHOL = new Zchol(A);
CHOL = A.CHOL;
}
else
CHOL = new Zchol(A);
return Solve.aib(CHOL.R, Solve.ahib(CHOL.R, B));
}
/**
Solves XA = B, where A is a Zpsdmat and B is a Zmat.
@param B The right-hand side
@param A The matrix of the sysem
@return BA-1
@exception JampackException
Thrown for nonsquare matrix or nonconformity.
Passed from below.
*/
public static Zmat bai(Zmat B, Zpsdmat A)
throws JampackException{
Zchol CHOL;
A.getProperties();
B.getProperties();
if (A.nr != A.nc)
throw new JampackException
("Rectangular matrix.");
if (A.nr != B.nc)
throw new JampackException
("Inconsistent dimensions.");
if (Parameters.History){
A.clean();
if (A.CHOL == null)
A.CHOL = new Zchol(A);
CHOL = A.CHOL;
}
else
CHOL = new Zchol(A);
return Solve.bahi(Solve.bai(B, CHOL.R), CHOL.R);
}
}