Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > vectors > AbstractDoubleVector

 `1 package JSci.maths.vectors;2 3 import JSci.GlobalSettings;4 import JSci.maths.ExtraMath;5 import JSci.maths.Mapping;6 import JSci.maths.algebras.*;7 import JSci.maths.fields.*;8 import JSci.maths.groups.AbelianGroup;9 10 /**11 * The AbstractDoubleVector class encapsulates vectors containing doubles.12 * @version 1.013 * @author Mark Hale14 */15 public abstract class AbstractDoubleVector extends MathVector implements BanachSpace.Member {16         protected AbstractDoubleVector(final int dim) {17                 super(dim);18         }19         /**20         * Compares two double vectors for equality.21         * Two vectors are considered to be equal if the norm of their difference is within the zero tolerance.22         * @param obj a double vector23         */24         public final boolean equals(Object obj) {25         return equals(obj, GlobalSettings.ZERO_TOL);26         }27     public boolean equals(Object obj, double tol) {28                 if(obj != null && (obj instanceof AbstractDoubleVector)) {29                         final AbstractDoubleVector vec = (AbstractDoubleVector) obj;30                         return (this.dimension() == vec.dimension() && this.subtract(vec).norm() <= tol);31                 } else32                         return false;33         }34         /**35         * Returns a comma delimited string representing the value of this vector.36         */37         public String toString() {38                 final StringBuffer buf = new StringBuffer (8*N);39                 int i;40                 for(i=0; in-norm.71         * @jsci.planetmath VectorPnorm72         */73         public double norm(int n) {74                 double answer = Math.pow(Math.abs(getComponent(0)), n);75                 for(int i=1; i2-norm (magnitude).81         * @jsci.planetmath VectorPnorm82         */83         public double norm() {84                 double answer = getComponent(0);85                 for(int i=1; i-norm.91         * @author Taber Smith92         * @jsci.planetmath VectorPnorm93         */94         public double infNorm() {95                 double infNorm = Math.abs(getComponent(0));96                 for(int i=1; i infNorm)99                                 infNorm = abs;100                 }101                 return infNorm;102         }103         /**104         * Returns the mass (l1-norm).105         */106         public double mass() {107                 double mass=0.0;108                 for(int i=1; i