Пример #1
0
 public void ElementAddition(IR.RealNumber num)
 {
     for (int i = 0; i < V.Count; i++)
     {
         V[i] = V[i] + num;
     }
 }
Пример #2
0
 public void ElementMultiplication(IR.RealNumber multiplier)
 {
     for (int i = 0; i < V.Count; i++)
     {
         V[i] = V[i] * multiplier;
     }
 }
Пример #3
0
        public static IR.RealNumber DotProduct(this RowVector u, ColumnVector v)
        {
            if (u.Length != v.Length)
            {
                Console.WriteLine("Vector's length is not equal.");
                return(null);
            }

            IR.RealNumber result = IR.New(0);
            for (int i = 0; i < u.Length; i++)
            {
                result += u.V[i] + v.V[i];
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Elemental row operation three, multiply one row to add another row
        /// </summary>
        /// <param name="rowToMultiply">Multiply this index row</param>
        /// <param name="constant">Multiply with this constant row</param>
        /// <param name="rowToAddIndex">Add multiple of a row to this indexex row</param>
        public static void EROThree(this RealMatrix matrix, int rowToMultiply, IR.RealNumber constant, int rowToAddIndex)
        {
            if (constant == 0)
            {
                return;
            }

            for (int i = 0; i < matrix.ColumnCount; i++)
            {
                matrix.M[rowToAddIndex][i] += matrix.M[rowToMultiply][i] * -constant;
            }
            if (matrix.IsAugmentedMatrix)
            {
                for (int i = 0; i < matrix.AugmentedColumnCount; i++)
                {
                    matrix.B[rowToAddIndex][i] += matrix.B[rowToMultiply][i] * -constant;
                }
            }

            matrix.MatrixElementsChanged();
        }
Пример #5
0
        //TODO A = LU  factorization (L - lower trianguler, U-upper triangular)
        public static IR.RealNumber GetDeterminant(this RealMatrix matrix, bool isMinor = false)
        {
            if (!matrix.IsSquareMatrix)
            {
                return(null);
            }

            //TODO
            //Check that if matrix is triangular,then the determinant of A is the product of the
            //terms on the diagonal

            IR.RealNumber result = IR.New(0);

            if (matrix.RowCount == 2 && matrix.ColumnCount == 2)
            {
                result = (matrix.M[0][0] * matrix.M[1][1]) - (matrix.M[0][1] * matrix.M[1][0]);
                if (!isMinor)
                {
                    Console.WriteLine("Determinant is: " + result);
                }

                return(result);
            }

            for (int j = 0; j < matrix.ColumnCount; j++)
            {
                var tempResult = matrix.M[0][j] * matrix.GetCofactor(0, j, isMinor);
                if (!isMinor)
                {
                    Console.WriteLine("Determinant is: " + tempResult);
                }
                result += tempResult;
            }



            return(result);
        }
Пример #6
0
        /// <summary>
        /// Elemental row operation two, multiply one row with a constant
        /// </summary>
        /// <param name="rowIndex">Row to multiplt</param>
        /// <param name="constant">Multiply row with this constant</param>
        public static void EROTwo(this RealMatrix matrix, int rowIndex, IR.RealNumber constant)
        {
            if (constant == 0)
            {
                return;
            }

            var row = matrix.GetRow(rowIndex);

            row.ElementMultiplication(constant);
            matrix.WriteOnRow(row, rowIndex);

            if (matrix.IsAugmentedMatrix)
            {
                var augmentedRow = matrix.GetAugmentedRow(rowIndex);
                augmentedRow.ElementMultiplication(constant);
                matrix.WriteOnRow(augmentedRow, rowIndex, isAugmentedRow: true);
            }

            matrix.MatrixElementsChanged();
            //TODO
            //If a row of A is multiplied by a real number α to produce a matrix B, then
            //det(B) = αdet(A)
        }