JScience v4.3

Package org.jscience.mathematics.vector

Provides support for linear algebra in the form of matrices and vectors.

See:
          Description

Class Summary
ComplexMatrix This class represents an optimized matrix implementation for complex numbers.
ComplexVector This class represents an optimized vector implementation for complex numbers elements.
DenseMatrix<F extends Field<F>> This class represents a matrix made of dense vectors (as rows).
DenseVector<F extends Field<F>> This class represents a dense vector.
Float64Matrix This class represents an optimized matrix implementation for 64 bits floating-point numbers.
Float64Vector This class represents an optimized vector implementation for 64 bits floating point elements.
LUDecomposition<F extends Field<F>> This class represents the decomposition of a matrix A into a product of a lower and upper triangular matrices, L and U respectively, such as A = P·L·U with P a permutation matrix.
Matrix<F extends Field<F>> This class represents a rectangular table of elements of a ring-like algebraic structure.
SparseMatrix<F extends Field<F>> This class represents a matrix made of sparse vectors (as rows).
SparseVector<F extends Field<F>> This class represents a sparse vector.
Vector<F extends Field<F>> This class represents an immutable element of a vector space.
 

Exception Summary
DimensionException Signals that an operation is performed upon vectors or matrices whose dimensions disagree.
 

Package org.jscience.mathematics.vector Description

Provides support for linear algebra in the form of matrices and vectors.

With the Matrix class, you should be able to resolve linear systems of equations involving any kind of elements such as Rational, ModuloInteger (modulo operations), Complex, RationalFunction, etc. The main requirement being that your element class implements the mathematical Field interface.

Most numbers and even invertible matrices themselves may implement this interface. Non-commutative multiplication is supported which allows for the resolution of systems of equations with invertible matrix coefficients (matrices of matrices).

For classes embedding automatic error calculation (e.g. Real or Amount), the error on the solution obtained tells you if can trust that solution or not (e.g. system close to singularity). The following example illustrates this point.

Let's say you have a simple electric circuit composed of 2 resistors in series with a battery. You want to know the voltage (U1, U2) at the nodes of the resistors and the current (I) traversing the circuit.

    import static org.jscience.physics.units.SI.*;
    
            Amount<ElectricResistance> R1 = Amount.valueOf(100, 1, OHM); // 1% precision. 
            Amount<ElectricResistance> R2 = Amount.valueOf(300, 3, OHM); // 1% precision.
            Amount<ElectricPotential> U0 = Amount.valueOf(28, 0.01, VOLT); // ±0.01 V fluctuation.

            // Equations:  U0 = U1 + U2       |1  1  0 |   |U1|   |U0|
            //             U1 = R1 * I    =>  |-1 0  R1| * |U2| = |0 |
            //             U2 = R2 * I        |0 -1  R2|   |I |   |0 |
            //
            //                                    A      *  X   =  B
            //
            DenseMatrix<Amount<?>> A = DenseMatrix.valueOf(new Amount<?>[][] {
                { Amount.ONE,            Amount.ONE,            Amount.valueOf(0, OHM) },
                { Amount.ONE.opposite(), Amount.ZERO,           R1 },
                { Amount.ZERO,           Amount.ONE.opposite(), R2 } });
            DenseVector<Amount<?>> B = DenseVector.valueOf(new Amount<?>[] 
                { U0, Amount.valueOf(0, VOLT), Amount.valueOf(0, VOLT) });
            Vector<Amount<?>> X = A.solve(B);
            System.out.println(X);
            System.out.println(X.get(2).to(MILLI(AMPERE)));

        > {(7.0 ± 1.6E-1) V, (21.0 ± 1.5E-1) V, (7.0E-2 ± 7.3E-4) V/Ω}
        > (70.0 ± 7.3E-1) mA
        
Because the Amount class guarantees the accuracy/precision of its calculations. As long as the input resistances, voltage stay within their specification range then the current is guaranteed to be (70.0 ± 7.3E-1) mA. When the inputs have no error specified, the error on the result corresponds to calculations numeric errors only (which might increase significantly if the matrix is close to singularity).


JScience v4.3

Copyright © 2006 JScience.