001: package JSci.physics.quantum;
002:
003: import JSci.maths.Complex;
004: import JSci.maths.Member;
005: import JSci.maths.DimensionException;
006: import JSci.maths.MaximumIterationsExceededException;
007: import JSci.maths.matrices.AbstractComplexSquareMatrix;
008: import JSci.maths.vectors.AbstractComplexVector;
009: import JSci.maths.vectors.ComplexVector;
010:
011: /**
012: * The Operator class provides an object for encapsulating quantum mechanical operators.
013: * @version 1.5
014: * @author Mark Hale
015: */
016: public class Operator implements Member {
017: protected AbstractComplexSquareMatrix representation;
018:
019: /**
020: * Constructs an operator given a matrix representation.
021: * @param rep a matrix representation
022: */
023: public Operator(AbstractComplexSquareMatrix rep) {
024: representation = rep;
025: }
026:
027: /**
028: * Compares two operators for equality.
029: * @param a an operator
030: */
031: public boolean equals(Object a) {
032: return representation.equals(((Operator) a).representation);
033: }
034:
035: /**
036: * Returns a string representing this operator.
037: */
038: public String toString() {
039: return representation.toString();
040: }
041:
042: /**
043: * Returns a hashcode for this operator.
044: */
045: public int hashCode() {
046: return (int) Math.exp(trace().mod());
047: }
048:
049: /**
050: * Returns the representation.
051: */
052: public AbstractComplexSquareMatrix getRepresentation() {
053: return representation;
054: }
055:
056: /**
057: * Returns true if this operator is self-adjoint.
058: */
059: public boolean isSelfAdjoint() {
060: return representation.isHermitian();
061: }
062:
063: /**
064: * Returns true if this operator is unitary.
065: */
066: public boolean isUnitary() {
067: return representation.isUnitary();
068: }
069:
070: /**
071: * Returns the trace.
072: */
073: public Complex trace() {
074: return representation.trace();
075: }
076:
077: /**
078: * Returns the operator norm.
079: */
080: public double norm() {
081: try {
082: return representation.operatorNorm();
083: } catch (MaximumIterationsExceededException e) {
084: return -1.0;
085: }
086: }
087:
088: /**
089: * Returns the dimension.
090: */
091: public int dimension() {
092: return representation.columns();
093: }
094:
095: public Object getSet() {
096: return representation.getSet();
097: }
098:
099: //============
100: // OPERATIONS
101: //============
102:
103: // ADDITION
104:
105: /**
106: * Returns the addition of this operator and another.
107: * @param op an operator
108: * @exception MatrixDimensionException If the operators have different dimensions.
109: */
110: public Operator add(Operator op) {
111: return new Operator(representation.add(op.representation));
112: }
113:
114: // SUBTRACTION
115:
116: /**
117: * Returns the subtraction of this operator and another.
118: * @param op an operator
119: * @exception MatrixDimensionException If the operators have different dimensions.
120: */
121: public Operator subtract(Operator op) {
122: return new Operator(representation.subtract(op.representation));
123: }
124:
125: // MULTIPLICATION
126:
127: /**
128: * Returns the multiplication of this operator and another.
129: * @param op an operator
130: * @exception MatrixDimensionException If the operators have different dimensions.
131: */
132: public Operator multiply(Operator op) {
133: return new Operator(representation.multiply(op.representation));
134: }
135:
136: /**
137: * Returns the multiplication of this operator and a ket vector.
138: * @param ket a ket vector
139: * @exception DimensionException If the operator and vector have different dimensions.
140: */
141: public KetVector multiply(KetVector ket) {
142: int opDim = dimension();
143: if (opDim == ket.dimension()) {
144: AbstractComplexVector ketRep = ket.getRepresentation();
145: Complex tmp, array[] = new Complex[opDim];
146: for (int j, i = 0; i < opDim; i++) {
147: tmp = representation.getElement(i, 0).multiply(
148: ketRep.getComponent(0));
149: for (j = 1; j < opDim; j++)
150: tmp = tmp.add(representation.getElement(i, j)
151: .multiply(ketRep.getComponent(j)));
152: array[i] = tmp;
153: }
154: return new KetVector(new ComplexVector(array));
155: } else
156: throw new DimensionException(
157: "Operator and vector have different dimensions.");
158: }
159: }
|