KickJava   Java API By Example, From Geeks To Geeks.

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


1 package JSci.physics.quantum;
2
3 import JSci.maths.matrices.AbstractComplexMatrix;
4 import JSci.maths.matrices.AbstractComplexSquareMatrix;
5
6 /**
7 * The DensityMatrix class provides an object for encapsulating density matrices.
8 * @version 1.5
9 * @author Mark Hale
10 */

11 public final class DensityMatrix extends Operator {
12         private static AbstractComplexSquareMatrix constructor(KetVector kets[],double probs[]) {
13                 AbstractComplexMatrix rep=(new Projector(kets[0])).getRepresentation().scalarMultiply(probs[0]);
14                 for(int i=1;i<kets.length;i++)
15                         rep=rep.add((new Projector(kets[i])).getRepresentation().scalarMultiply(probs[i]));
16                 return (AbstractComplexSquareMatrix)rep;
17         }
18         private static AbstractComplexSquareMatrix constructor(Projector projs[],double probs[]) {
19                 AbstractComplexMatrix rep=projs[0].getRepresentation().scalarMultiply(probs[0]);
20                 for(int i=1;i<projs.length;i++)
21                         rep=rep.add(projs[i].getRepresentation().scalarMultiply(probs[i]));
22                 return (AbstractComplexSquareMatrix)rep;
23         }
24
25         /**
26         * Constructs a density matrix.
27         * @param kets an array of ket vectors
28         * @param probs the probabilities of being in the ket vector states.
29         */

30         public DensityMatrix(KetVector kets[],double probs[]) {
31                 super(constructor(kets,probs));
32         }
33         /**
34         * Constructs a density matrix.
35         * @param projs an array of projectors
36         * @param probs the probabilities of being in the projector states.
37         */

38         public DensityMatrix(Projector projs[],double probs[]) {
39                 super(constructor(projs,probs));
40         }
41         /**
42         * Returns true if this density matrix is a pure state.
43         */

44         public boolean isPureState() {
45                 return representation.equals(representation.multiply(representation));
46         }
47 }
48
49
Popular Tags