Java API By Example, From Geeks To Geeks.

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

 `1 package JSci.maths.vectors;2 3 import JSci.maths.ExtraMath;4 import JSci.maths.MathDouble;5 import JSci.maths.MathInteger;6 import JSci.maths.Mapping;7 import JSci.maths.algebras.Module;8 import JSci.maths.algebras.VectorSpace;9 import JSci.maths.fields.Ring;10 import JSci.maths.fields.Field;11 import JSci.maths.groups.AbelianGroup;12 13 /**14 * An array-based implementation of a double vector.15 * @version 2.116 * @author Mark Hale17 */18 public class DoubleVector extends AbstractDoubleVector {19         /**20         * Array containing the components of the vector.21         */22         protected double vector[];23         /**24         * Constructs an empty vector.25         * @param dim the dimension of the vector.26         */27         public DoubleVector(final int dim) {28                 super(dim);29                 vector=new double[dim];30         }31         /**32         * Constructs a vector by wrapping an array.33         * @param array an assigned value.34         */35         public DoubleVector(final double array[]) {36                 super(array.length);37                 vector=array;38         }39         /**40         * Compares two double vectors for equality.41         * @param a a double vector.42         */43         public boolean equals(Object a, double tol) {44                 if(a!=null && (a instanceof AbstractDoubleVector) && N==((AbstractDoubleVector)a).N) {45                         final AbstractDoubleVector dv=(AbstractDoubleVector)a;46                         double sumSqr = 0.0;47                         for(int i=0; i=0 && n=0 && nn-norm.110         * @jsci.planetmath VectorPnorm111         */112         public double norm(int n) {113                 double answer=Math.pow(Math.abs(vector[0]), n);114                 for(int i=1; i2-norm (magnitude).120         * @jsci.planetmath VectorPnorm121         */122         public double norm() {123                 double answer=vector[0];124                 for(int i=1;i-norm.130         * @author Taber Smith131         * @jsci.planetmath VectorPnorm132         */133         public double infNorm() {134                 double infNorm = Math.abs(vector[0]);135                 for(int i=1; i infNorm)138                                 infNorm = abs;139                 }140                 return infNorm;141         }142 143 //============144 // OPERATIONS145 //============146 147         /**148         * Returns the negative of this vector.149         */150         public AbelianGroup.Member negate() {151                 final double array[]=new double[N];152                 array[0]=-vector[0];153                 for(int i=1;i