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

JSci.maths.vectors.AbstractComplexVector 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.maths.vectors;

import JSci.GlobalSettings;
import JSci.maths.Complex;
import JSci.maths.ComplexMapping;
import JSci.maths.algebras.*;
import JSci.maths.fields.*;
import JSci.maths.groups.AbelianGroup;

/**
* The AbstractComplexVector class encapsulates vectors containing complex numbers.
* @version 1.0
* @author Mark Hale
*/
public abstract class AbstractComplexVector extends MathVector implements HilbertSpace.Member {
        protected AbstractComplexVector(final int dim) {
                super(dim);
        }
        /**
        * Compares two complex vectors for equality.
        * Two vectors are considered to be equal if the norm of their difference is within the zero tolerance.
        * @param obj a complex vector
        */
        public final boolean equals(Object obj) {
		return equals(obj, GlobalSettings.ZERO_TOL);
        }
	public boolean equals(Object obj, double tol) {
                if(obj != null && (obj instanceof AbstractComplexVector)) {
                        final AbstractComplexVector vec = (AbstractComplexVector) obj;
                        return (this.dimension() == vec.dimension() && this.subtract(vec).norm() <= tol);
                } else
                        return false;
        }
        /**
        * Returns a comma delimited string representing the value of this vector.
        */
        public String toString() {
                final StringBuffer buf = new StringBuffer(12*N);
                int i;
                for(i=0; i2-norm (magnitude).
        */
        public double norm() {
                double answer = getRealComponent(0)*getRealComponent(0) + getImagComponent(0)*getImagComponent(0);
                for(int i=1;iinfinity-norm.
        */
        public double infNorm() {
                double infNorm = getComponent(0).mod();
                for(int i=1;i infNorm)
                                infNorm = mod;
                }
                return infNorm;
        }

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

        /**
        * Returns the complex conjugate of this vector.
        */
        public abstract AbstractComplexVector conjugate();
        /**
        * Returns the addition of this vector and another.
        * @param v a complex vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public abstract AbstractComplexVector add(AbstractComplexVector v);
        /**
        * Returns the subtraction of this vector by another.
        * @param v a complex vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public abstract AbstractComplexVector subtract(AbstractComplexVector v);
        /**
        * Returns the multiplication of this vector by a scalar.
        * @param z a complex number
        */
        public abstract AbstractComplexVector scalarMultiply(Complex z);
        /**
        * Returns the multiplication of this vector by a scalar.
        * @param x a double
        */
        public abstract AbstractComplexVector scalarMultiply(double x);
        /**
        * Returns the division of this vector by a scalar.
        * @param z a complex number
        * @exception ArithmeticException If divide by zero.
        */
        public abstract AbstractComplexVector scalarDivide(Complex z);
        /**
        * Returns the division of this vector by a scalar.
        * @param x a double
        * @exception ArithmeticException If divide by zero.
        */
        public abstract AbstractComplexVector scalarDivide(double x);
        /**
        * Returns a normalised vector (a vector with norm equal to one).
        */
        public AbstractComplexVector normalize() {
                return this.scalarDivide(norm());
        }
        /**
        * Returns the scalar product of this vector and another.
        * @param v a complex vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public abstract Complex scalarProduct(AbstractComplexVector v);
        /**
        * Applies a function on all the vector components.
        * @param f a user-defined function
        * @return a complex vector
        */
        public abstract AbstractComplexVector mapComponents(ComplexMapping f);
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy