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

JSci.maths.vectors.AbstractIntegerVector 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.maths.ExtraMath;
import JSci.maths.groups.AbelianGroup;
import JSci.maths.fields.Ring;
import JSci.maths.algebras.Module;

/**
* The AbstractIntegerVector class encapsulates vectors containing integers.
* @version 1.0
* @author Mark Hale
*/
public abstract class AbstractIntegerVector extends MathVector {
        protected AbstractIntegerVector(final int dim) {
                super(dim);
        }
        /**
        * Compares two integer vectors for equality.
        * Two vectors are considered to be equal if the norm of their difference is zero.
        * @param obj an integer vector
        */
        public boolean equals(Object obj) {
                if(obj != null && (obj instanceof AbstractIntegerVector)) {
                        final AbstractIntegerVector vec = (AbstractIntegerVector) obj;
                        return (this.dimension() == vec.dimension() && this.subtract(vec).norm() == 0.0);
                } else
                        return false;
        }
        /**
        * Returns a comma delimited string representing the value of this vector.
        */
        public String toString() {
                final StringBuffer buf = new StringBuffer(8*N);
                int i;
                for(i=0; in-norm.
        */
        public double norm(final int n) {
                double answer = Math.pow(Math.abs(getComponent(0)), n);
                for(int i=1; i2-norm (magnitude).
        */
        public double norm() {
                double answer = getComponent(0);
                for(int i=1; iinfinity-norm.
        * @author Taber Smith
        */
        public double infNorm() {
                int infNorm = Math.abs(getComponent(0));
                for(int i=1; i infNorm)
                                infNorm = abs;
                }
                return infNorm;
        }

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

        /**
        * Returns the addition of this vector and another.
        * @param v an integer vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public abstract AbstractIntegerVector add(AbstractIntegerVector v);
        /**
        * Returns the subtraction of this vector by another.
        * @param v an integer vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public abstract AbstractIntegerVector subtract(AbstractIntegerVector v);
        /**
        * Returns the multiplication of this vector by a scalar.
        * @param x an integer
        */
        public abstract AbstractIntegerVector scalarMultiply(int x);
        /**
        * Returns the scalar product of this vector and another.
        * @param v an integer vector
        * @exception VectorDimensionException If the vectors are different sizes.
        */
        public abstract int scalarProduct(AbstractIntegerVector v);
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy