JADE v6.1

Package com.dautelle.math

Provides support for linear algebra.

See:
          Description

Interface Summary
Operable This interface abstracts the fundamental arithmetic operations: plus (+), times (*), opposite (-) and reciprocal (1/).
 

Class Summary
LUDecomposition This class represents the decomposition of a Matrix into a product of lower and upper triangular matrices (L and U, respectively).
Matrix This class represents a rectangular array of Operable objects.
Vector This class represents an element of a vector space arranged as single column Matrix.
 

Exception Summary
DimensionException Thrown when an operation is performed upon two matrices whose dimensions disagree.
 

Package com.dautelle.math Description

Provides support for linear algebra.

Using the Matrix class, you will be able to resolve linear systems of equations involving any kind of elements such as LargeInteger (modulo operations), Complex, Function, etc. The only requirement being that your elements implement the interface Operable (basically any class which defines the additive and multiplicative operations as well as their respective inverses).

All numbers types and the matrix class itself implement the Operable interface. Non-commutative multiplication is supported which allows for the resolution of systems of equations with matrix coefficients (matrices of matrices).

For classes embedding automatic error calculation (e.g. reals or quantities), 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.

        ElectricResistance R1 = (ElectricResistance) Quantity.valueOf(100, 0.1, SI.OHM); // 0.1% error.
        ElectricResistance R2 = (ElectricResistance) Quantity.valueOf(300, 0.3, SI.OHM); // 0.1% error
        ElectricPotential U0 = (ElectricPotential) Quantity.valueOf(28, 0.1, SI.VOLT);

        // 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
        //
        Matrix A = Matrix.valueOf(new Quantity[][]{
                {Scalar.ONE,          Scalar.ONE,          ElectricResistance.ZERO},
                {Scalar.ONE.negate(), Scalar.ZERO,         R1},
                {Scalar.ZERO,         Scalar.ONE.negate(), R2}});
        Vector B = Vector.valueOf(new Quantity[]{
                U0, ElectricPotential.ZERO, ElectricPotential.ZERO});
        Vector X = (Vector) A.lu().solve(B);
        ElectricCurrent.showAs(SI.MILLI(SI.AMPERE));
        System.out.println(X);
        System.out.println("Estimated current = " + ((Quantity) X.get(2)).doubleValue());
        System.out.println("Absolute error  = " + ((Quantity) X.get(2)).getAbsoluteError());

        > {7 V, 21 V, 70 mA}
        > Estimated current = 0.070000320000327
        > Absolute error  = 3.2000032000058243E-4
As you can see the estimated current (70.00032 mA) is slightly higher than the current you would get using real numbers (28.0 / 400.0 = 70mA). This is due to the errors on the input values (R1, R2, U0) and the fact that the relationship between the resistors and the current is not linear (I = U/R). The estimated value is the median value of the quantity interval. In this particular case, the current is guaranteed to be: 70.00032 ±0.32 mA. If the inputs have no error specified, the error on the result corresponds to calculations numeric errors only.


JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.