Java API By Example, From Geeks To Geeks.

# Java > Open Source Codes > JSci > maths > vectors > AbstractIntegerVector

 1 package JSci.maths.vectors;2 3 import JSci.maths.ExtraMath;4 import JSci.maths.groups.AbelianGroup;5 import JSci.maths.fields.Ring;6 import JSci.maths.algebras.Module;7 8 /**9 * The AbstractIntegerVector class encapsulates vectors containing integers.10 * @version 1.011 * @author Mark Hale12 */13 public abstract class AbstractIntegerVector extends MathVector {14         protected AbstractIntegerVector(final int dim) {15                 super(dim);16         }17         /**18         * Compares two integer vectors for equality.19         * Two vectors are considered to be equal if the norm of their difference is zero.20         * @param obj an integer vector21         */22         public boolean equals(Object obj) {23                 if(obj != null && (obj instanceof AbstractIntegerVector)) {24                         final AbstractIntegerVector vec = (AbstractIntegerVector) obj;25                         return (this.dimension() == vec.dimension() && this.subtract(vec).norm() == 0.0);26                 } else27                         return false;28         }29         /**30         * Returns a comma delimited string representing the value of this vector.31         */32         public String toString() {33                 final StringBuffer buf = new StringBuffer (8*N);34                 int i;35                 for(i=0; in-norm.76         */77         public double norm(final int n) {78                 double answer = Math.pow(Math.abs(getComponent(0)), n);79                 for(int i=1; i2-norm (magnitude).85         */86         public double norm() {87                 double answer = getComponent(0);88                 for(int i=1; i-norm.94         * @author Taber Smith95         */96         public double infNorm() {97                 int infNorm = Math.abs(getComponent(0));98                 for(int i=1; i infNorm)101                                 infNorm = abs;102                 }103                 return infNorm;104         }105 106 //============107 // OPERATIONS108 //============109 110         /**111         * Returns the addition of this vector and another.112         * @param v an integer vector113         * @exception VectorDimensionException If the vectors are different sizes.114         */115         public abstract AbstractIntegerVector add(AbstractIntegerVector v);116         /**117         * Returns the subtraction of this vector by another.118         * @param v an integer vector119         * @exception VectorDimensionException If the vectors are different sizes.120         */121         public abstract AbstractIntegerVector subtract(AbstractIntegerVector v);122         /**123         * Returns the multiplication of this vector by a scalar.124         * @param x an integer125         */126         public abstract AbstractIntegerVector scalarMultiply(int x);127         /**128         * Returns the scalar product of this vector and another.129         * @param v an integer vector130         * @exception VectorDimensionException If the vectors are different sizes.131         */132         public abstract int scalarProduct(AbstractIntegerVector v);133 }134 135 Popular Tags