KickJava   Java API By Example, From Geeks To Geeks.

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


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_RDim2 class encapsulates sp(2,R) algebras using
14 * the 2 dimensional (fundamental) 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_RDim2 extends LieAlgebra {
20         private final static Complex t1[][]={
21                 {Complex.ZERO,ComplexField.HALF},
22                 {ComplexField.HALF,Complex.ZERO}
23         };
24         private final static Complex t2[][]={
25                 {Complex.ZERO,ComplexField.HALF},
26                 {ComplexField.MINUS_HALF,Complex.ZERO}
27         };
28         private final static Complex t3[][]={
29                 {ComplexField.HALF,Complex.ZERO},
30                 {Complex.ZERO,ComplexField.MINUS_HALF}
31         };
32         /**
33         * Basis.
34         */

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

45         private sp2_RDim2() {
46                 super("sp(2,R) [2]");
47         }
48         /**
49         * Singleton.
50         */

51         public static final sp2_RDim2 getInstance() {
52                 return _instance;
53         }
54         /**
55         * Returns an element as a matrix (vector*basis).
56         */

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

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

79         public AbstractComplexSquareMatrix[] basis() {
80                 return basisMatrices;
81         }
82 }
83
84
Popular Tags