All Downloads are FREE. Search and download functionalities are using the official Maven repository.

JSci.physics.quantum.KetVector Maven / Gradle / Ivy

Go to download

JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software. It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ... Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).

The newest version!
package JSci.physics.quantum;

import JSci.maths.Complex;
import JSci.maths.vectors.MathVector;
import JSci.maths.vectors.AbstractComplexVector;
import JSci.maths.vectors.ComplexVector;
import JSci.maths.matrices.ComplexSquareMatrix;
import JSci.maths.DimensionException;
import JSci.maths.vectors.VectorDimensionException;
import JSci.maths.groups.AbelianGroup;
import JSci.maths.algebras.Module;
import JSci.maths.fields.Ring;

/**
* The KetVector class provides an object for encapsulating Dirac ket vectors.
* @version 1.5
* @author Mark Hale
*/
public final class KetVector extends MathVector {
        private AbstractComplexVector representation;

        /**
        * Constructs a ket vector given a vector representation.
        * @param rep a vector representation
        */
        public KetVector(AbstractComplexVector rep) {
                super(rep.dimension());
                representation=rep;
        }
        /**
        * Compares two ket vectors for equality.
        * @param a a ket vector
        */
        public boolean equals(Object a) {
                return representation.equals(((KetVector)a).representation);
        }
        /**
        * Returns a comma delimited string representing the value of this ket vector.
        */
        public String toString() {
                return representation.toString();
        }
        /**
        * Returns a hashcode for this ket vector.
        */
        public int hashCode() {
                return representation.hashCode();
        }
        /**
        * Map this ket vector to a bra vector.
        */
        public BraVector toBraVector() {
                return new BraVector(representation.conjugate());
        }
        /**
        * Returns the representation.
        */
        public AbstractComplexVector getRepresentation() {
                return representation;
        }
        /**
        * Returns the norm.
        */
        public double norm() {
                return representation.norm();
        }
	public Object getSet() {
		return representation.getSet();
	}

//============
// OPERATIONS
//============

        /**
        * Returns the negative of this vector.
        */
        public AbelianGroup.Member negate() {
                return representation.negate();
        }

// ADDITION

        /**
        * Returns the addition of this vector and another.
        */
        public AbelianGroup.Member add(AbelianGroup.Member v) {
                if(v instanceof KetVector)
                        return add((KetVector)v);
                else
                        throw new IllegalArgumentException("Vector class not recognised by this method.");
        }
        /**
        * Returns the addition of this vector and another.
        * @param v a ket vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public KetVector add(KetVector v) {
                return new KetVector(representation.add(v.representation));
        }

// SUBTRACTION

        /**
        * Returns the subtraction of this vector by another.
        */
        public AbelianGroup.Member subtract(AbelianGroup.Member v) {
                if(v instanceof KetVector)
                        return subtract((KetVector)v);
                else
                        throw new IllegalArgumentException("Vector class not recognised by this method.");
        }
        /**
        * Returns the subtraction of this vector by another.
        * @param v a ket vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public KetVector subtract(KetVector v) {
                return new KetVector(representation.subtract(v.representation));
        }

// MULTIPLICATION

        /**
        * Returns the multiplication of this ket vector by a scalar.
        */
        public Module.Member scalarMultiply(Ring.Member x) {
                return representation.scalarMultiply(x);
        }
        /**
        * Returns the multiplication of this ket vector and a bra vector.
        * @param bra a bra vector
        * @exception VectorDimensionException If the vectors have different dimensions.
        */
        public Operator multiply(BraVector bra) {
                final int ketDim=dimension();
                if(ketDim==bra.dimension()) {
                        AbstractComplexVector braRep=bra.getRepresentation();
                        Complex array[][]=new Complex[ketDim][ketDim];
                        for(int j,i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy