Exemplo n.º 1
0
        public 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) < epsilon)
                {
                    throw new ArgumentException("Diagonal element is too small!");
                }
                x[i] = (b[i] - VectorR.DotProduct(A.GetRowVector(i), x)) / d;
            }
            return(x);
        }
Exemplo n.º 2
0
        public MatrixR LUInverse(MatrixR m)
        {
            int     n = m.GetRows();
            MatrixR u = m.Identity();

            LUDecompose(m);
            VectorR uv = new VectorR(n);

            for (int i = 0; i < n; i++)
            {
                uv = u.GetRowVector(i);
                LUSubstitute(m, uv);
                u.ReplaceRow(uv, i);
            }
            MatrixR inv = u.GetTranspose();

            return(inv);
        }