jvx.numeric
Class PnMatrix
- java.lang.Object
-
- jvx.numeric.PnMatrix
-
public class PnMatrix extends java.lang.ObjectNumerical routines for bigger matrix linear algebra problems. Methods are taken from Numerical Recipes and adapted such that all array indices start with 0 rather than the standard fortran 1.- See Also:
PdMatrix- Author:
- Konrad Polthier
- Version:
- 21.02.05, 1.30 revised (ep) New method
tridag.
11.01.05, 1.20 revised (ep) New methods for solving symmetric pentadiagonal systems.
20.07.99, 1.00 revised (kp) All array indices start at 0.
20.07.99, 1.00 created (kp)
-
-
Constructor Summary
Constructors Constructor and Description PnMatrix()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static booleancyclic(double[] a, double[] b, double[] c, double[] r, double[] x, double[] bb, double[] u, double[] z, double[] tmp, int n, double eps)Solves the equationAu=r, whereAis a cyclic tridiagonal matrix with diagonalb, lower offdiagonalaand upper offdiagonalc.static doubledeterminant(double[][] aIn, int n)Compute determinant of a given NxN matrix A.static booleaninvert(double[][] y, double[][] aIn, int n)Invert a given NxN matrix A and return its invers.static voidlubksb(double[][] a, int n, int[] indx, double[] b)Solves the set of N linear equations AX=B.static doubleludcmp(double[][] a, int n, int[] indx)Given an NxN matrix A this routine replaces it by the LU decomposition of a rowwise permutation of itself.static voidmain(java.lang.String[] args)Test routine for matrix inversion.static booleanpenpes(int n, double[] a, double[] b, double[] c, double[] f, double[] d, double[] e, double[] h, double eps)Solves a linear system of equations with penta-diagonal, symmetric coefficient matrix with additional perodicity coefficients (1,n-1),(1,n) and (2,n).static booleanpentas(int n, double[] a, double[] b, double[] c, double[] f, double eps)Solves a linear system of equations with penta-diagonal, symmetric coefficient matrix.static booleantridag(double[] a, double[] b, double[] c, double[] r, double[] u, double[] tmp, int n, double eps)Solves the equationAu=r, whereAis a tridiagonal matrix with diagonalb, lower offdiagonalaand upper offdiagonalc.
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
Test routine for matrix inversion.
-
invert
public static boolean invert(double[][] y, double[][] aIn, int n)Invert a given NxN matrix A and return its invers. Apply LU decomposition. A and N are input. Y is output containing the invers of matrix A. Input matrix is not modified since copied to a temporary matrix. All array indices start with 0 rather than the standard fortran 1.- Returns:
- false if A was singular and therefore LU failed.
- See Also:
ludcmp(double[][], int, int[]),lubksb(double[][], int, int[], double[])- Author:
- Konrad Polthier
- Version:
- 08.09.99, 1.20 revised (kp) Keep input matrix untouched.
07.09.99, 1.10 revised (kp) Return false instead of throwing ArithmeticException.
20.07.99, 1.00 created (kp)
-
determinant
public static double determinant(double[][] aIn, int n)Compute determinant of a given NxN matrix A. Apply LU decomposition. A and N are input. Y is output containing the invers of matrix A. Input matrix is not modified since copied to a temporary matrix.All array indices start with 0 rather than the standard fortran 1.
- Returns:
- determinant, or 0. if matrix is singular.
- See Also:
ludcmp(double[][], int, int[]),lubksb(double[][], int, int[], double[])- Author:
- Konrad Polthier
- Version:
- 15.04.06, 1.20 revised (kp) Singular matrix just returns 0, but issues no warning.
08.09.99, 1.10 revised (kp) Keep input matrix untouched.
20.07.99, 1.00 created (kp)
-
ludcmp
public static double ludcmp(double[][] a, int n, int[] indx) throws java.lang.ArithmeticExceptionGiven an NxN matrix A this routine replaces it by the LU decomposition of a rowwise permutation of itself. A and N are input. A is output, arranged as in equation (2.3.14) described in Numerical Recipes; INDX is an output vector which record the row permutation effected by the partial pivoting; the return value is +/-1 depending on whether the number of row interchanges was even (1.) or odd (-1.). This routine is used in combination with LUBKSB to solve linear equations or invert a matrix.This version is taken from Numerical Recipes and adapted such that all array indices start with 0 rather than the standard fortran 1.
- Throws:
java.lang.ArithmeticException- if A was singular.- See Also:
lubksb(double[][], int, int[], double[])- Author:
- Numerical Recipes, changed to Java and adapted by Konrad Polthier
- Version:
- 20.07.99, 1.00 revised (kp) All array indices start at 0.
20.07.99, 1.00 created (kp)
-
lubksb
public static void lubksb(double[][] a, int n, int[] indx, double[] b)Solves the set of N linear equations AX=B. Here A is input, not as the matrix A but rather as its LU decomposition, determined by the routine LUDCMP. INDX is input as the permutation vector returned by LUDCMP. B is input as the right-hand side vector B, and returns with the solution vector X. A, N, NP and INDX are not modified by the routine and can be left in place for successive calls with different right-hand sides B. This routine takes into account the possibility that B will begin with many zero elements, so it is efficient for the use in matrix inversion.This version is taken from Numerical Recipes and adapted such that all array indices start with 0 rather than the standard fortran 1.
- See Also:
ludcmp(double[][], int, int[])- Author:
- Numerical Recipes, changed to Java and adapted by Konrad Polthier
- Version:
- 20.07.99, 1.00 revised (kp) All array indices start at 0.
20.07.99, 1.00 created (kp)
-
pentas
public static final boolean pentas(int n, double[] a, double[] b, double[] c, double[] f, double eps)Solves a linear system of equations with penta-diagonal, symmetric coefficient matrix. The arrays a, b, c and f are modified by the routine.- Parameters:
n- dimension of matrix; must be greater or equal to 3a- diagonal of length nb- 1st side diagonal of length n-1 (but array must be of length n)c- 2nd side diagonal of length n-2 (but array must be of length n)f- input: right hand side; output: solutioneps- precision; recommended is 10^(-t+2) where t is machine precision- Returns:
- true at success; false if matrix is (numerically) singular
- Author:
- From 'Eindimensionale Spline-Interpolations-Algorithmen, H. Späth', ported to Java by Eike Preuss
-
penpes
public static final boolean penpes(int n, double[] a, double[] b, double[] c, double[] f, double[] d, double[] e, double[] h, double eps)Solves a linear system of equations with penta-diagonal, symmetric coefficient matrix with additional perodicity coefficients (1,n-1),(1,n) and (2,n). The arrays a, b, c and f are modified by the routine.- Parameters:
n- dimension of matrix; must be greater or equal to 5a- diagonal of length nb- 1st side diagonal of length n-1; and b[n-1] must contain matrix element (1,n)c- 2nd side diagonal of length n-2; and b[n-2],b[n-1] must contain matrix elements (1,n-1),(2,n)f- input: right hand side; output: solutiond- helper array of length ne- helper array of length nh- helper array of length neps- precision; recommended is 10^(-t+2) where t is machine precision- Returns:
- true at success; false if matrix is (numerically) singular
- Author:
- From 'Eindimensionale Spline-Interpolations-Algorithmen, H. Späth', ported to Java by Eike Preuss
-
tridag
public static boolean tridag(double[] a, double[] b, double[] c, double[] r, double[] u, double[] tmp, int n, double eps)Solves the equationAu=r, whereAis a tridiagonal matrix with diagonalb, lower offdiagonalaand upper offdiagonalc.Input vectors
a,b,candrare not modified. The method only succeeds if no pivoting is required!- Parameters:
a- lower offdiagonal; only the entries 1,...,n-1 are usedb- diagonalc- upper offdiagonal; only the entries 0,...,n-2 are usedr- right hand sideu- output: solutiontmp- temporary vector of sizen; may be nulln- dimension of matrix/vectorseps- precision- Returns:
- true at success
- Version:
- 21.02.05, 1.00 created (ep) Created and adapted from numerical recipes (2.4).
-
cyclic
public static boolean cyclic(double[] a, double[] b, double[] c, double[] r, double[] x, double[] bb, double[] u, double[] z, double[] tmp, int n, double eps)Solves the equationAu=r, whereAis a cyclic tridiagonal matrix with diagonalb, lower offdiagonalaand upper offdiagonalc.Input vectors
a,b,candrare not modified. The method only succeeds if no pivoting is required!- Parameters:
a- lower offdiagonal; contains the element in upper right corner asa[0]b- diagonalc- upper offdiagonal; contains the element in lower left corner asc[n-1]r- right hand sidex- output: solutionbb- temporary vector of sizen; may be nullu- temporary vector of sizen; may be nullz- temporary vector of sizen; may be nulltmp- temporary vector of sizen; may be nulln- dimension of matrix/vectorseps- precision- Returns:
- true at success
- Version:
- 22.02.05, 1.00 created (ep) Created and adapted from numerical recipes (2.7).
-
-
"