KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractComplexSquareMatrix;
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 BraVector class provides an object for encapsulating Dirac bra vectors.
16 * @version 1.5
17 * @author Mark Hale
18 */

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

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

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

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

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

52         public KetVector toKetVector() {
53                 return new KetVector(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 BraVector)
89                         return add((BraVector)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 bra vector
96         * @exception VectorDimensionException If the vectors are different sizes.
97         */

98         public BraVector add(BraVector v) {
99                 return new BraVector(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 BraVector)
109                         return subtract((BraVector)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 bra vector
116         * @exception VectorDimensionException If the vectors are different sizes.
117         */

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

124         /**
125         * Returns the multiplication of this bra 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 bra vector and a ket vector.
132         * @param ket a ket vector
133         * @exception VectorDimensionException If the vectors have different dimensions.
134         */

135         public Complex multiply(KetVector ket) {
136                 final int braDim=dimension();
137                 if(braDim==ket.dimension()) {
138                         AbstractComplexVector ketRep=ket.getRepresentation();
139                         Complex answer=representation.getComponent(0).multiply(ketRep.getComponent(0));
140                         for(int i=1;i<braDim;i++)
141                                 answer=answer.add(representation.getComponent(i).multiply(ketRep.getComponent(i)));
142                         return answer;
143                 } else
144                         throw new VectorDimensionException("Vectors have different dimensions.");
145         }
146         /**
147         * Returns the multiplication of this bra vector and an operator.
148         * @param op an operator
149         * @exception DimensionException If the operator and vector have different dimensions.
150         */

151         public BraVector multiply(Operator op) {
152                 final int braDim=dimension();
153                 if(braDim==op.dimension()) {
154                         AbstractComplexSquareMatrix opRep=op.getRepresentation();
155                         Complex tmp,array[]=new Complex[braDim];
156                         for(int j,i=0;i<braDim;i++) {
157                                 tmp=representation.getComponent(0).multiply(opRep.getElement(0,i));
158                                 for(j=1;j<braDim;j++)
159                                         tmp=tmp.add(representation.getComponent(j).multiply(opRep.getElement(j,i)));
160                                 array[i]=tmp;
161                         }
162                         return new BraVector(new ComplexVector(array));
163                 } else
164                         throw new DimensionException("Operator and vector have different dimensions.");
165         }
166 }
167
168
Popular Tags