Java API By Example, From Geeks To Geeks.

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

 `1 package JSci.maths.vectors;2 3 import JSci.maths.Complex;4 import JSci.maths.ComplexMapping;5 import JSci.maths.MathDouble;6 import JSci.maths.MathInteger;7 import JSci.maths.algebras.Module;8 import JSci.maths.algebras.VectorSpace;9 import JSci.maths.algebras.HilbertSpace;10 import JSci.maths.fields.Ring;11 import JSci.maths.fields.Field;12 import JSci.maths.groups.AbelianGroup;13 14 /**15 * An array-based implementation of a complex vector.16 * @version 2.217 * @author Mark Hale18 */19 public class ComplexVector extends AbstractComplexVector {20         /**21         * Arrays containing the components of the vector.22         */23         protected double vectorRe[];24         protected double vectorIm[];25         /**26         * Constructs an empty vector.27         * @param dim the dimension of the vector.28         */29         public ComplexVector(final int dim) {30                 super(dim);31                 vectorRe=new double[dim];32                 vectorIm=new double[dim];33         }34         /**35         * Constructs a vector by wrapping two arrays.36         * @param real an array of real values37         * @param imag an array of imaginary values38         */39         public ComplexVector(final double real[],final double imag[]) {40                 super(real.length);41                 vectorRe=real;42                 vectorIm=imag;43         }44         /**45         * Constructs a vector from an array.46         * @param array an assigned value47         */48         public ComplexVector(final Complex array[]) {49                 this(array.length);50                 for(int i=0;i=0 && n=0 && n=0 && n=0 && n=0 && n2-norm (magnitude).151         */152         public double norm() {153                 double answer=vectorRe[0]*vectorRe[0]+vectorIm[0]*vectorIm[0];154                 for(int i=1;i-norm.160         */161         public double infNorm() {162                 double infNorm=vectorRe[0]*vectorRe[0]+vectorIm[0]*vectorIm[0];163                 for(int i=1;iinfNorm)166                                 infNorm=mod;167                 }168                 return Math.sqrt(infNorm);169         }170 171 //============172 // OPERATIONS173 //============174 175         /**176         * Returns the negative of this vector.177         */178         public AbelianGroup.Member negate() {179                 final double arrayRe[]=new double[N];180                 final double arrayIm[]=new double[N];181                 arrayRe[0]=-vectorRe[0];182                 arrayIm[0]=-vectorIm[0];183                 for(int i=1;i