KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > physics > quantum > KetVector


1 package JSci.physics.quantum;
2
3 import JSci.maths.Complex;
4 import JSci.maths.vectors.MathVector;
5 import JSci.maths.vectors.AbstractComplexVector;
6 import JSci.maths.vectors.ComplexVector;
7 import JSci.maths.matrices.ComplexSquareMatrix;
8 import JSci.maths.DimensionException;
9 import JSci.maths.vectors.VectorDimensionException;
10 import JSci.maths.groups.AbelianGroup;
11 import JSci.maths.algebras.Module;
12 import JSci.maths.fields.Ring;
13
14 /**
15 * The KetVector class provides an object for encapsulating Dirac ket vectors.
16 * @version 1.5
17 * @author Mark Hale
18 */

19 public final class KetVector extends MathVector {
20         private AbstractComplexVector representation;
21
22         /**
23         * Constructs a ket vector given a vector representation.
24         * @param rep a vector representation
25         */

26         public KetVector(AbstractComplexVector rep) {
27                 super(rep.dimension());
28                 representation=rep;
29         }
30         /**
31         * Compares two ket vectors for equality.
32         * @param a a ket vector
33         */

34         public boolean equals(Object JavaDoc a) {
35                 return representation.equals(((KetVector)a).representation);
36         }
37         /**
38         * Returns a comma delimited string representing the value of this ket vector.
39         */

40         public String JavaDoc toString() {
41                 return representation.toString();
42         }
43         /**
44         * Returns a hashcode for this ket vector.
45         */

46         public int hashCode() {
47                 return representation.hashCode();
48         }
49         /**
50         * Map this ket vector to a bra vector.
51         */

52         public BraVector toBraVector() {
53                 return new BraVector(representation.conjugate());
54         }
55         /**
56         * Returns the representation.
57         */

58         public AbstractComplexVector getRepresentation() {
59                 return representation;
60         }
61         /**
62         * Returns the norm.
63         */

64         public double norm() {
65                 return representation.norm();
66         }
67     public Object JavaDoc getSet() {
68         return representation.getSet();
69     }
70
71 //============
72
// OPERATIONS
73
//============
74

75         /**
76         * Returns the negative of this vector.
77         */

78         public AbelianGroup.Member negate() {
79                 return representation.negate();
80         }
81
82 // ADDITION
83

84         /**
85         * Returns the addition of this vector and another.
86         */

87         public AbelianGroup.Member add(AbelianGroup.Member v) {
88                 if(v instanceof KetVector)
89                         return add((KetVector)v);
90                 else
91                         throw new IllegalArgumentException JavaDoc("Vector class not recognised by this method.");
92         }
93         /**
94         * Returns the addition of this vector and another.
95         * @param v a ket vector
96         * @exception VectorDimensionException If the vectors are different sizes.
97         */

98         public KetVector add(KetVector v) {
99                 return new KetVector(representation.add(v.representation));
100         }
101
102 // SUBTRACTION
103

104         /**
105         * Returns the subtraction of this vector by another.
106         */

107         public AbelianGroup.Member subtract(AbelianGroup.Member v) {
108                 if(v instanceof KetVector)
109                         return subtract((KetVector)v);
110                 else
111                         throw new IllegalArgumentException JavaDoc("Vector class not recognised by this method.");
112         }
113         /**
114         * Returns the subtraction of this vector by another.
115         * @param v a ket vector
116         * @exception VectorDimensionException If the vectors are different sizes.
117         */

118         public KetVector subtract(KetVector v) {
119                 return new KetVector(representation.subtract(v.representation));
120         }
121
122 // MULTIPLICATION
123

124         /**
125         * Returns the multiplication of this ket vector by a scalar.
126         */

127         public Module.Member scalarMultiply(Ring.Member x) {
128                 return representation.scalarMultiply(x);
129         }
130         /**
131         * Returns the multiplication of this ket vector and a bra vector.
132         * @param bra a bra vector
133         * @exception VectorDimensionException If the vectors have different dimensions.
134         */

135         public Operator multiply(BraVector bra) {
136                 final int ketDim=dimension();
137                 if(ketDim==bra.dimension()) {
138                         AbstractComplexVector braRep=bra.getRepresentation();
139                         Complex array[][]=new Complex[ketDim][ketDim];
140                         for(int j,i=0;i<ketDim;i++) {
141                                 array[i][0]=representation.getComponent(i).multiply(braRep.getComponent(0));
142                                 for(j=1;j<ketDim;j++)
143                                         array[i][j]=representation.getComponent(i).multiply(braRep.getComponent(j));
144                         }
145                         return new Operator(new ComplexSquareMatrix(array));
146                 } else
147                         throw new VectorDimensionException("Vectors have different dimensions.");
148         }
149 }
150
151
Popular Tags