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 19 public final class KetVector extends MathVector { 20 private AbstractComplexVector representation; 21 22 26 public KetVector(AbstractComplexVector rep) { 27 super(rep.dimension()); 28 representation=rep; 29 } 30 34 public boolean equals(Object a) { 35 return representation.equals(((KetVector)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 BraVector toBraVector() { 53 return new BraVector(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 KetVector) 89 return add((KetVector)v); 90 else 91 throw new IllegalArgumentException ("Vector class not recognised by this method."); 92 } 93 98 public KetVector add(KetVector v) { 99 return new KetVector(representation.add(v.representation)); 100 } 101 102 104 107 public AbelianGroup.Member subtract(AbelianGroup.Member v) { 108 if(v instanceof KetVector) 109 return subtract((KetVector)v); 110 else 111 throw new IllegalArgumentException ("Vector class not recognised by this method."); 112 } 113 118 public KetVector subtract(KetVector v) { 119 return new KetVector(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 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 |