Java API By Example, From Geeks To Geeks.

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

 `1 package JSci.maths.vectors;2 3 import JSci.GlobalSettings;4 import JSci.maths.Complex;5 import JSci.maths.ComplexMapping;6 import JSci.maths.algebras.*;7 import JSci.maths.fields.*;8 import JSci.maths.groups.AbelianGroup;9 10 /**11 * The AbstractComplexVector class encapsulates vectors containing complex numbers.12 * @version 1.013 * @author Mark Hale14 */15 public abstract class AbstractComplexVector extends MathVector implements HilbertSpace.Member {16         protected AbstractComplexVector(final int dim) {17                 super(dim);18         }19         /**20         * Compares two complex 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 complex 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 AbstractComplexVector)) {29                         final AbstractComplexVector vec = (AbstractComplexVector) 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 (12*N);39                 int i;40                 for(i=0; i2-norm (magnitude).91         */92         public double norm() {93                 double answer = getRealComponent(0)*getRealComponent(0) + getImagComponent(0)*getImagComponent(0);94                 for(int i=1;i-norm.100         */101         public double infNorm() {102                 double infNorm = getComponent(0).mod();103                 for(int i=1;i infNorm)106                                 infNorm = mod;107                 }108                 return infNorm;109         }110 111 //============112 // OPERATIONS113 //============114 115         /**116         * Returns the complex conjugate of this vector.117         */118         public abstract AbstractComplexVector conjugate();119         /**120         * Returns the addition of this vector and another.121         * @param v a complex vector122         * @exception VectorDimensionException If the vectors are different sizes.123         */124         public abstract AbstractComplexVector add(AbstractComplexVector v);125         /**126         * Returns the subtraction of this vector by another.127         * @param v a complex vector128         * @exception VectorDimensionException If the vectors are different sizes.129         */130         public abstract AbstractComplexVector subtract(AbstractComplexVector v);131         /**132         * Returns the multiplication of this vector by a scalar.133         * @param z a complex number134         */135         public abstract AbstractComplexVector scalarMultiply(Complex z);136         /**137         * Returns the multiplication of this vector by a scalar.138         * @param x a double139         */140         public abstract AbstractComplexVector scalarMultiply(double x);141         /**142         * Returns the division of this vector by a scalar.143         * @param z a complex number144         * @exception ArithmeticException If divide by zero.145         */146         public abstract AbstractComplexVector scalarDivide(Complex z);147         /**148         * Returns the division of this vector by a scalar.149         * @param x a double150         * @exception ArithmeticException If divide by zero.151         */152         public abstract AbstractComplexVector scalarDivide(double x);153         /**154         * Returns a normalised vector (a vector with norm equal to one).155         */156         public AbstractComplexVector normalize() {157                 return this.scalarDivide(norm());158         }159         /**160         * Returns the scalar product of this vector and another.161         * @param v a complex vector162         * @exception VectorDimensionException If the vectors are different sizes.163         */164         public abstract Complex scalarProduct(AbstractComplexVector v);165         /**166         * Applies a function on all the vector components.167         * @param f a user-defined function168         * @return a complex vector169         */170         public abstract AbstractComplexVector mapComponents(ComplexMapping f);171 }172 173 ` Popular Tags