Example #1
0
        public RVector GetUnitVector()
        {
            RVector result = new RVector(vector);

            result.Normalize();
            return(result);
        }
Example #2
0
        public RVector Clone()
        {
            RVector v = new RVector(vector);

            v.vector = (double[])vector.Clone();
            return(v);
        }
Example #3
0
        public static double DotProduct(RVector v1, RVector v2)
        {
            double result = 0.0;

            for (int i = 0; i < v1.ndim; i++)
            {
                result += v1[i] * v2[i];
            }
            return(result);
        }
Example #4
0
        public static RVector operator *(RVector v, double d)
        {
            RVector result = new RVector(v.ndim);

            for (int i = 0; i < v.ndim; i++)
            {
                result[i] = v[i] * d;
            }
            return(result);
        }
Example #5
0
        public static RVector operator /(double d, RVector v)
        {
            RVector result = new RVector(v.ndim);

            for (int i = 0; i < v.ndim; i++)
            {
                result[i] = v[i] / d;
            }
            return(result);
        }
Example #6
0
        public static RVector operator -(RVector v1, RVector v2)
        {
            RVector result = new RVector(v1.ndim);

            for (int i = 0; i < v1.ndim; i++)
            {
                result[i] = v1[i] - v2[i];
            }
            return(result);
        }
Example #7
0
        public RVector GetColVector(int n)
        {
            if (n < 0 || n > nCols)
            {
                throw new Exception("n-th col is out of range!");
            }
            RVector ColVector = new RVector(nRows);

            for (int i = 0; i < nRows; i++)
            {
                ColVector[i] = matrix[i, n];
            }
            return(ColVector);
        }
Example #8
0
        public RVector GetRowVector(int m)
        {
            if (m < 0 || m > nRows)
            {
                throw new Exception("m-th row is out of range!");
            }
            RVector RowVector = new RVector(nCols);

            for (int i = 0; i < nCols; i++)
            {
                RowVector[i] = matrix[m, i];
            }
            return(RowVector);
        }
Example #9
0
 public RMatrix ReplaceCol(RVector vec, int n)
 {
     if (n < 0 || n > nCols)
     {
         throw new Exception("n-th col is out of range!");
     }
     if (vec.GetVectorSize != nRows)
     {
         throw new Exception("Vector ndim is out of range!");
     }
     for (int i = 0; i < nRows; i++)
     {
         matrix[i, n] = vec[i];
     }
     return(new RMatrix(matrix));
 }
Example #10
0
 public RMatrix ReplaceRow(RVector vec, int m)
 {
     if (m < 0 || m > nRows)
     {
         throw new Exception("m-th row is out of range!");
     }
     if (vec.GetVectorSize != nCols)
     {
         throw new Exception("Vector ndim is out of range!");
     }
     for (int i = 0; i < nCols; i++)
     {
         matrix[m, i] = vec[i];
     }
     return(new RMatrix(matrix));
 }
Example #11
0
        public static RVector CrossProduct(RVector v1, RVector v2)
        {
            if (v1.ndim != 3)
            {
                throw new Exception("Vector v1 must be 3 dimensional!");
            }
            if (v2.ndim != 3)
            {
                throw new Exception("Vector v2 must be 3 dimensional!");
            }
            RVector result = new RVector(3);

            result[0] = v1[1] * v2[2] - v1[2] * v2[1];
            result[1] = v1[2] * v2[0] - v1[0] * v2[2];
            result[2] = v1[0] * v2[1] - v1[1] * v2[0];
            return(result);
        }
Example #12
0
        public static RMatrix Transform(RVector v1, RVector v2)
        {
            if (v1.GetVectorSize != v2.GetVectorSize)
            {
                throw new Exception("The vectors must have the same ndim!");
            }
            RMatrix result = new RMatrix(v1.GetVectorSize, v1.GetVectorSize);

            for (int i = 0; i < v1.GetVectorSize; i++)
            {
                for (int j = 0; j < v1.GetVectorSize; j++)
                {
                    result[j, i] = v1[i] * v2[j];
                }
            }
            return(result);
        }
Example #13
0
        public static RVector Transform(RVector vec, RMatrix mat)
        {
            RVector result = new RVector(vec.GetVectorSize);

            if (!mat.IsSquared())
            {
                throw new Exception("The matrix must be squared!");
            }
            if (mat.GetnRows != vec.GetVectorSize)
            {
                throw new Exception("The ndim of the vector must be equal"
                                    + " to the number of rows of the matrix!");
            }
            for (int i = 0; i < mat.GetnRows; i++)
            {
                result[i] = 0.0;
                for (int j = 0; j < mat.GetnCols; j++)
                {
                    result[i] += vec[j] * mat[j, i];
                }
            }
            return(result);
        }
Example #14
0
 public bool Equals(RVector v)
 {
     return(vector == v.vector);
 }