numl.Math.LinearAlgebra.Matrix.Forward C# (CSharp) Метод

Forward() статический приватный Метод

Forwards.
static private Forward ( Matrix A, Vector b ) : Vector
A Matrix Input Matrix.
b Vector The Vector to process.
Результат Vector
        internal static Vector Forward(Matrix A, Vector b)
        {
            Vector x = Vector.Zeros(b.Length);
            for (int i = 0; i < b.Length; i++)
            {
                double sum = 0;
                for (int j = 0; j < i; j++)
                    sum += A[i, j] * x[j];

                x[i] = (b[i] - sum) / A[i, i];
            }

            return x;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Solves Ax = b for x If A is not square or the system is overdetermined, this operation solves
        /// the linear least squares A.T * A x = A.T * b.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="A">Matrix A.</param>
        /// <param name="b">Vector b.</param>
        /// <returns>x.</returns>
        public static Vector operator /(Matrix A, Vector b)
        {
            if (A.Rows != b.Length)
            {
                throw new InvalidOperationException("Matrix row count does not match vector length!");
            }

            // LLS
            if (A.Rows != A.Cols)
            {
                Matrix C = A.T * A;
                Matrix L = C.Cholesky();
                Vector d = (A.T * b).ToVector();
                Vector z = Matrix.Forward(L, d);
                Vector x = Matrix.Backward(L.T, z);
                return(x);
            }
            // regular solve
            else
            {
                // need to be smarter here....
                return(((A ^ -1) * b).ToVector());
            }
        }