KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > algebras > sp2_RDim3


1 package JSci.maths.algebras;
2
3 import JSci.maths.*;
4 import JSci.maths.matrices.AbstractComplexMatrix;
5 import JSci.maths.matrices.AbstractComplexSquareMatrix;
6 import JSci.maths.matrices.ComplexSquareMatrix;
7 import JSci.maths.vectors.AbstractDoubleVector;
8 import JSci.maths.vectors.Double3Vector;
9 import JSci.maths.vectors.VectorDimensionException;
10 import JSci.maths.fields.ComplexField;
11
12 /**
13 * The sp2_RDim3 class encapsulates sp(2,R) algebras using
14 * the 3 dimensional (adjoint) representation.
15 * Elements are represented by 3-vectors with a matrix basis.
16 * @version 1.2
17 * @author Mark Hale
18 */

19 public final class sp2_RDim3 extends LieAlgebra {
20         private final static Complex t1[][]={
21                 {Complex.ZERO,Complex.ZERO,ComplexField.MINUS_HALF},
22                 {Complex.ZERO,Complex.ZERO,ComplexField.HALF},
23                 {ComplexField.MINUS_TWO,ComplexField.TWO,Complex.ZERO}
24         };
25         private final static Complex t2[][]={
26                 {Complex.ZERO,Complex.ZERO,ComplexField.MINUS_HALF},
27                 {Complex.ZERO,Complex.ZERO,ComplexField.MINUS_HALF},
28                 {ComplexField.TWO,ComplexField.TWO,Complex.ZERO}
29         };
30         private final static Complex t3[][]={
31                 {Complex.ONE,Complex.ZERO,Complex.ZERO},
32                 {Complex.ZERO,ComplexField.MINUS_ONE,Complex.ZERO},
33                 {Complex.ZERO,Complex.ZERO,Complex.ZERO}
34         };
35         /**
36         * Basis.
37         */

38         private final static AbstractComplexSquareMatrix basisMatrices[]={
39                 new ComplexSquareMatrix(t1),
40                 new ComplexSquareMatrix(t2),
41                 new ComplexSquareMatrix(t3)
42         };
43
44         private final static sp2_RDim3 _instance = new sp2_RDim3();
45         /**
46         * Constructs an sp(2,R) algebra.
47         */

48         private sp2_RDim3() {
49                 super("sp(2,R) [3]");
50         }
51         /**
52         * Singleton.
53         */

54         public static final sp2_RDim3 getInstance() {
55                 return _instance;
56         }
57         /**
58         * Returns an element as a matrix (vector*basis).
59         */

60         public AbstractComplexSquareMatrix getElement(final AbstractDoubleVector v) {
61                 AbstractComplexMatrix m=basisMatrices[0].scalarMultiply(v.getComponent(0));
62                 m=m.add(basisMatrices[1].scalarMultiply(v.getComponent(1)));
63                 m=m.add(basisMatrices[2].scalarMultiply(v.getComponent(2)));
64                 return (AbstractComplexSquareMatrix)m.scalarMultiply(Complex.I);
65         }
66         /**
67         * Returns the Lie bracket (commutator) of two elements.
68         * Same as the vector cross product.
69         */

70         public AbstractDoubleVector multiply(final AbstractDoubleVector a, final AbstractDoubleVector b) {
71                 if(!(a instanceof Double3Vector) || !(b instanceof Double3Vector))
72                         throw new VectorDimensionException("Vectors must be 3-vectors.");
73                 return new Double3Vector(
74                         a.getComponent(2)*b.getComponent(1)-a.getComponent(1)*b.getComponent(2),
75                         a.getComponent(2)*b.getComponent(0)-a.getComponent(0)*b.getComponent(2),
76                         a.getComponent(1)*b.getComponent(0)-a.getComponent(0)*b.getComponent(1)
77                 );
78         }
79         /**
80         * Returns the basis used to represent the Lie algebra.
81         */

82         public AbstractComplexSquareMatrix[] basis() {
83                 return basisMatrices;
84         }
85 }
86
87
Popular Tags