1 package JSci.physics.quantum; 2 3 import JSci.maths.Complex; 4 import JSci.maths.Member; 5 import JSci.maths.DimensionException; 6 import JSci.maths.MaximumIterationsExceededException; 7 import JSci.maths.matrices.AbstractComplexSquareMatrix; 8 import JSci.maths.vectors.AbstractComplexVector; 9 import JSci.maths.vectors.ComplexVector; 10 11 16 public class Operator implements Member { 17 protected AbstractComplexSquareMatrix representation; 18 19 23 public Operator(AbstractComplexSquareMatrix rep) { 24 representation=rep; 25 } 26 30 public boolean equals(Object a) { 31 return representation.equals(((Operator)a).representation); 32 } 33 36 public String toString() { 37 return representation.toString(); 38 } 39 42 public int hashCode() { 43 return (int)Math.exp(trace().mod()); 44 } 45 48 public AbstractComplexSquareMatrix getRepresentation() { 49 return representation; 50 } 51 54 public boolean isSelfAdjoint() { 55 return representation.isHermitian(); 56 } 57 60 public boolean isUnitary() { 61 return representation.isUnitary(); 62 } 63 66 public Complex trace() { 67 return representation.trace(); 68 } 69 72 public double norm() { 73 try { 74 return representation.operatorNorm(); 75 } catch(MaximumIterationsExceededException e) { 76 return -1.0; 77 } 78 } 79 82 public int dimension() { 83 return representation.columns(); 84 } 85 public Object getSet() { 86 return representation.getSet(); 87 } 88 89 93 95 100 public Operator add(Operator op) { 101 return new Operator(representation.add(op.representation)); 102 } 103 104 106 111 public Operator subtract(Operator op) { 112 return new Operator(representation.subtract(op.representation)); 113 } 114 115 117 122 public Operator multiply(Operator op) { 123 return new Operator(representation.multiply(op.representation)); 124 } 125 130 public KetVector multiply(KetVector ket) { 131 int opDim=dimension(); 132 if(opDim==ket.dimension()) { 133 AbstractComplexVector ketRep=ket.getRepresentation(); 134 Complex tmp,array[]=new Complex[opDim]; 135 for(int j,i=0;i<opDim;i++) { 136 tmp=representation.getElement(i,0).multiply(ketRep.getComponent(0)); 137 for(j=1;j<opDim;j++) 138 tmp=tmp.add(representation.getElement(i,j).multiply(ketRep.getComponent(j))); 139 array[i]=tmp; 140 } 141 return new KetVector(new ComplexVector(array)); 142 } else 143 throw new DimensionException("Operator and vector have different dimensions."); 144 } 145 } 146 147 | Popular Tags |