示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }