1 package JSci.maths.vectors; 2 3 import JSci.maths.ExtraMath; 4 import JSci.maths.groups.AbelianGroup; 5 import JSci.maths.fields.Ring; 6 import JSci.maths.algebras.Module; 7 8 13 public abstract class AbstractIntegerVector extends MathVector { 14 protected AbstractIntegerVector(final int dim) { 15 super(dim); 16 } 17 22 public boolean equals(Object obj) { 23 if(obj != null && (obj instanceof AbstractIntegerVector)) { 24 final AbstractIntegerVector vec = (AbstractIntegerVector) obj; 25 return (this.dimension() == vec.dimension() && this.subtract(vec).norm() == 0.0); 26 } else 27 return false; 28 } 29 32 public String toString() { 33 final StringBuffer buf = new StringBuffer (8*N); 34 int i; 35 for(i=0; i<N-1; i++) { 36 buf.append(getComponent(i)); 37 buf.append(','); 38 } 39 buf.append(getComponent(i)); 40 return buf.toString(); 41 } 42 45 public int hashCode() { 46 return (int)Math.exp(norm()); 47 } 48 52 public AbstractDoubleVector toDoubleVector() { 53 final double array[]=new double[N]; 54 for(int i=0;i<N;i++) 55 array[i]=getComponent(i); 56 return new DoubleVector(array); 57 } 58 63 public abstract int getComponent(int n); 64 70 public abstract void setComponent(int n, int x); 71 public Object getSet() { 72 throw new RuntimeException ("Not implemented: file bug"); 73 } 74 77 public double norm(final int n) { 78 double answer = Math.pow(Math.abs(getComponent(0)), n); 79 for(int i=1; i<N; i++) 80 answer += Math.pow(Math.abs(getComponent(i)), n); 81 return Math.pow(answer, 1.0/n); 82 } 83 86 public double norm() { 87 double answer = getComponent(0); 88 for(int i=1; i<N; i++) 89 answer = ExtraMath.hypot(answer, getComponent(i)); 90 return answer; 91 } 92 96 public double infNorm() { 97 int infNorm = Math.abs(getComponent(0)); 98 for(int i=1; i<N; i++) { 99 final int abs = Math.abs(getComponent(i)); 100 if(abs > infNorm) 101 infNorm = abs; 102 } 103 return infNorm; 104 } 105 106 110 115 public abstract AbstractIntegerVector add(AbstractIntegerVector v); 116 121 public abstract AbstractIntegerVector subtract(AbstractIntegerVector v); 122 126 public abstract AbstractIntegerVector scalarMultiply(int x); 127 132 public abstract int scalarProduct(AbstractIntegerVector v); 133 } 134 135 | Popular Tags |