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 15 public abstract class AbstractComplexVector extends MathVector implements HilbertSpace.Member { 16 protected AbstractComplexVector(final int dim) { 17 super(dim); 18 } 19 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 } else 32 return false; 33 } 34 37 public String toString() { 38 final StringBuffer buf = new StringBuffer (12*N); 39 int i; 40 for(i=0; i<N-1; i++) { 41 buf.append(getComponent(i).toString()); 42 buf.append(','); 43 } 44 buf.append(getComponent(i).toString()); 45 return buf.toString(); 46 } 47 50 public int hashCode() { 51 return (int)Math.exp(norm()); 52 } 53 56 public abstract AbstractDoubleVector real(); 57 60 public abstract AbstractDoubleVector imag(); 61 66 public abstract Complex getComponent(int n); 67 public abstract double getRealComponent(int n); 68 public abstract double getImagComponent(int n); 69 76 public abstract void setComponent(int n, Complex z); 77 85 public abstract void setComponent(int n, double x, double y); 86 public Object getSet() { 87 throw new RuntimeException ("Not implemented: file bug"); 88 } 89 92 public double norm() { 93 double answer = getRealComponent(0)*getRealComponent(0) + getImagComponent(0)*getImagComponent(0); 94 for(int i=1;i<N;i++) 95 answer += getRealComponent(i)*getRealComponent(i) + getImagComponent(i)*getImagComponent(i); 96 return Math.sqrt(answer); 97 } 98 101 public double infNorm() { 102 double infNorm = getComponent(0).mod(); 103 for(int i=1;i<N;i++) { 104 double mod = getComponent(i).mod(); 105 if(mod > infNorm) 106 infNorm = mod; 107 } 108 return infNorm; 109 } 110 111 115 118 public abstract AbstractComplexVector conjugate(); 119 124 public abstract AbstractComplexVector add(AbstractComplexVector v); 125 130 public abstract AbstractComplexVector subtract(AbstractComplexVector v); 131 135 public abstract AbstractComplexVector scalarMultiply(Complex z); 136 140 public abstract AbstractComplexVector scalarMultiply(double x); 141 146 public abstract AbstractComplexVector scalarDivide(Complex z); 147 152 public abstract AbstractComplexVector scalarDivide(double x); 153 156 public AbstractComplexVector normalize() { 157 return this.scalarDivide(norm()); 158 } 159 164 public abstract Complex scalarProduct(AbstractComplexVector v); 165 170 public abstract AbstractComplexVector mapComponents(ComplexMapping f); 171 } 172 173 | Popular Tags |