public ArgumentsValue Function(MatrixValue M)
        {
            if (M.DimensionX != 2 && M.DimensionY != 2)
            {
                throw new YAMPOperationInvalidException("lsq", "because exactly two rows or columns are required.");
            }

            if (M.DimensionX > M.DimensionY)
            {
                return(Function(M.GetSubMatrix(0, 1, 0, M.DimensionX), M.GetSubMatrix(1, 2, 0, M.DimensionX)));
            }

            return(Function(M.GetSubMatrix(0, M.DimensionY, 0, 1), M.GetSubMatrix(0, M.DimensionY, 1, 2)));
        }
        /// <summary>
        /// Solve A*X = B
        /// </summary>
        /// <param name="B">A Matrix with as many rows as A and any number of columns.</param>
        /// <returns>X so that L*U*X = B(piv,:)</returns>
        public override MatrixValue Solve(MatrixValue B)
        {
            if (B.DimensionY != m)
            {
                throw new YAMPDifferentDimensionsException(B.DimensionY, 1, m, 1);
            }

            if (!this.IsNonSingular)
            {
                throw new YAMPMatrixFormatException(SpecialMatrixFormat.NonSingular.ToString());
            }

            // Copy right hand side with pivoting
            var nx = B.DimensionX;
            var X  = B.GetSubMatrix(piv, 0, nx).GetComplexMatrix();

            // Solve L*Y = B(piv,:)
            for (var k = 0; k < n; k++)
            {
                for (var i = k + 1; i < n; i++)
                {
                    for (var j = 0; j < nx; j++)
                    {
                        X[i][j] -= X[k][j] * LU[i][k];
                    }
                }
            }

            // Solve U*X = Y;
            for (var k = n - 1; k >= 0; k--)
            {
                for (var j = 0; j < nx; j++)
                {
                    X[k][j] = X[k][j] / LU[k][k];
                }

                for (var i = 0; i < k; i++)
                {
                    for (var j = 0; j < nx; j++)
                    {
                        X[i][j] -= X[k][j] * LU[i][k];
                    }
                }
            }

            return(new MatrixValue(X, piv.Length, nx));
        }
Exemple #3
0
        public MatrixValue Function(MatrixValue M)
        {
            if (M.IsVector)
            {
                return(M.VectorSort());
            }

            var result = new MatrixValue();

            for (var i = 0; i < M.DimensionY; i++)
            {
                var vec = M.GetSubMatrix(i, i + 1, 0, M.DimensionX);
                vec    = vec.VectorSort();
                result = result.AddRow(vec);
            }

            return(result);
        }
Exemple #4
0
        public MatrixValue Function(MatrixValue M)
        {
            if (!M.IsVector)
            {
                var result = new MatrixValue();

                for (var i = 0; i < M.DimensionY; i++)
                {
                    var vec = M.GetSubMatrix(i, i + 1, 0, M.DimensionX);
                    vec = vec.VectorSort();
                    result = result.AddRow(vec);
                }

                return result;
            }

            return M.VectorSort();
        }
Exemple #5
0
        /// <summary>
        /// Solve A*X = B
        /// </summary>
        /// <param name="B">A Matrix with as many rows as A and any number of columns.</param>
        /// <returns>X so that L*U*X = B(piv,:)</returns>
        public override MatrixValue Solve(MatrixValue B)
        {
            if (B.DimensionY != m)
                throw new YAMPDifferentDimensionsException(B.DimensionY, 1, m, 1);

            if (!this.IsNonSingular)
                throw new YAMPMatrixFormatException(SpecialMatrixFormat.NonSingular.ToString());

            // Copy right hand side with pivoting
            var nx = B.DimensionX;
            var X = B.GetSubMatrix(piv, 0, nx).GetComplexMatrix();

            // Solve L*Y = B(piv,:)
            for (var k = 0; k < n; k++)
            {
                for (var i = k + 1; i < n; i++)
                {
                    for (var j = 0; j < nx; j++)
                    {
                        X[i][j] -= X[k][j] * LU[i][k];
                    }
                }
            }

            // Solve U*X = Y;
            for (var k = n - 1; k >= 0; k--)
            {
                for (var j = 0; j < nx; j++)
                {
                    X[k][j] = X[k][j] / LU[k][k];
                }

                for (var i = 0; i < k; i++)
                {
                    for (var j = 0; j < nx; j++)
                    {
                        X[i][j] -= X[k][j] * LU[i][k];
                    }
                }
            }

            return new MatrixValue(X, piv.Length, nx);
        }