Ejemplo n.º 1
0
        public static VectorR GaussJordan(MatrixR A, VectorR b)
        {
            Triangulate(A, b);
            int     n = b.GetSize();
            VectorR x = new VectorR(n);

            for (int i = n - 1; i >= 0; i--)
            {
                double d = A[i, i];
                if (Math.Abs(d) < 1.0e-500)
                {
                    throw new ArgumentException("Diagonal element is too small!");
                }
                x[i] = (b[i] - VectorR.DotProduct(A.GetRowVector(i), x)) / d;
            }
            return(x);
        }
Ejemplo n.º 2
0
 public static VectorR TriVectorProduct(VectorR v1, VectorR v2, VectorR v3)
 {
     if (v1.size != 3)
     {
         throw new ArgumentOutOfRangeException(
                   "v1", v1, "Vector v1 must be 3 dimensional!");
     }
     if (v1.size != 3)
     {
         throw new ArgumentOutOfRangeException(
                   "v2", v2, "Vector v2 must be 3 dimensional!");
     }
     if (v1.size != 3)
     {
         throw new ArgumentOutOfRangeException(
                   "v3", v3, "Vector v3 must be 3 dimensional!");
     }
     return(v2 * VectorR.DotProduct(v1, v3) - v3 * VectorR.DotProduct(v1, v2));
 }
Ejemplo n.º 3
0
        public static MatrixR operator *(MatrixR m1, MatrixR m2)
        {
            if (m1.GetCols() != m2.GetRows())
            {
                throw new ArgumentOutOfRangeException(
                          "Columns", m1, "The numbers of columns of the first matrix must be equal to" +
                          " the number of rows of the second matrix!");
            }
            MatrixR result = new MatrixR(m1.GetRows(), m2.GetCols());
            VectorR v1     = new VectorR(m1.GetCols());
            VectorR v2     = new VectorR(m2.GetRows());

            for (int i = 0; i < m1.GetRows(); i++)
            {
                v1 = m1.GetRowVector(i);
                for (int j = 0; j < m2.GetCols(); j++)
                {
                    v2           = m2.GetColVector(j);
                    result[i, j] = VectorR.DotProduct(v1, v2);
                }
            }
            return(result);
        }