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 19 public final class BraVector extends MathVector { 20 private AbstractComplexVector representation; 21 22 26 public BraVector(AbstractComplexVector rep) { 27 super(rep.dimension()); 28 representation=rep; 29 } 30 34 public boolean equals(Object a) { 35 return representation.equals(((BraVector)a).representation); 36 } 37 40 public String toString() { 41 return representation.toString(); 42 } 43 46 public int hashCode() { 47 return representation.hashCode(); 48 } 49 52 public KetVector toKetVector() { 53 return new KetVector(representation.conjugate()); 54 } 55 58 public AbstractComplexVector getRepresentation() { 59 return representation; 60 } 61 64 public double norm() { 65 return representation.norm(); 66 } 67 public Object getSet() { 68 return representation.getSet(); 69 } 70 71 75 78 public AbelianGroup.Member negate() { 79 return representation.negate(); 80 } 81 82 84 87 public AbelianGroup.Member add(AbelianGroup.Member v) { 88 if(v instanceof BraVector) 89 return add((BraVector)v); 90 else 91 throw new IllegalArgumentException ("Vector class not recognised by this method."); 92 } 93 98 public BraVector add(BraVector v) { 99 return new BraVector(representation.add(v.representation)); 100 } 101 102 104 107 public AbelianGroup.Member subtract(AbelianGroup.Member v) { 108 if(v instanceof BraVector) 109 return subtract((BraVector)v); 110 else 111 throw new IllegalArgumentException ("Vector class not recognised by this method."); 112 } 113 118 public BraVector subtract(BraVector v) { 119 return new BraVector(representation.subtract(v.representation)); 120 } 121 122 124 127 public Module.Member scalarMultiply(Ring.Member x) { 128 return representation.scalarMultiply(x); 129 } 130 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 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 |