static public VectorNd operator *(double factor, VectorNd v) { VectorNd vn = new VectorNd(v.dim); for (int i = 0; i < vn.dim; ++i) { vn[i] = v[i] * factor; } return(vn); }
static public VectorNd operator /(VectorNd v, double factor) { if (Math.Abs(factor) < 1e-6) { throw new DivideByZeroException(); } VectorNd vn = new VectorNd(v.dim); for (int i = 0; i < vn.dim; ++i) { vn[i] = v[i] / factor; } return(vn); }
static public VectorNd operator -(VectorNd v1, VectorNd v2) { if (v1.dim != v2.dim) { return(null); } VectorNd v = new VectorNd(v1.dim); for (int i = 0; i < v.dim; ++i) { v[i] = v1[i] - v2[i]; } return(v); }
public double Dot(VectorNd v) { if (v.dim != this.dim) { return(0); } double sum = 0.0; for (int i = 0; i < dim; ++i) { sum += val[i] * v[i]; } return(sum); }
public override bool Equals(Object obj) { if (obj == null) { return(false); } VectorNd v = obj as VectorNd; if ((Object)v == null) { return(false); } bool isEqual = true; for (int i = 0; i < dim; ++i) { if (Math.Abs(val[i] - v[i]) < 1e-6) { isEqual = false; break; } } return(isEqual); }