Пример #1
0
        public static Matrix2x2 Copy(IMatrix2x2 matrix)
        {
            var newArray = new BigRational[2, 2];

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    newArray[i, j] = matrix.UnderlyingValues[i, j];
                }
            }

            return(new Matrix2x2(newArray));
        }
Пример #2
0
 public bool Equals(IMatrix2x2 matrix)
 {
     if (matrix.UnderlyingValues.Length != this.UnderlyingValues.Length)
     {
         return(false);
     }
     for (int i = 0; i < Order; i++)
     {
         for (int j = 0; j < Order; j++)
         {
             if (matrix.UnderlyingValues[i, j] != this.UnderlyingValues[i, j])
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #3
0
        protected BigRational[,] MultiplyBase(IMatrix2x2 left, IMatrix2x2 right)
        {
            var values = new BigRational[Order, Order];

            for (int rowIndex = 0; rowIndex < Order; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < Order; columnIndex++)
                {
                    BigRational value = 0;
                    for (int i = 0; i < Order; i++)
                    {
                        value += left.UnderlyingValues[rowIndex, i] * right.UnderlyingValues[i, columnIndex];
                    }

                    values[rowIndex, columnIndex] = value;
                }
            }
            return(values);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("I want to find a solution of system of:\n 1) TWO linear equations \n 2) THREE linear equations");
            int userChoice = Convert.ToInt32(Console.ReadLine());

            if (userChoice == 1)
            {
                double x1;
                double x2;

                Equation   eq  = new Equation();
                IMatrix2x2 eq2 = (IMatrix2x2)eq;
                eq2.SetValues(ref eq);
                eq2.Solution(out x1, out x2);
                Console.WriteLine();
                eq2.EquationOutput();
                Console.WriteLine();

                Console.WriteLine($"x = {x1}, y = {x2}");
            }
            else if (userChoice == 2)
            {
                double x1;
                double x2;
                double x3;

                Equation   eq  = new Equation();
                IMatrix3x3 eq3 = (IMatrix3x3)eq;
                eq3.SetValues(ref eq);
                eq3.Solution(out x1, out x2, out x3);
                Console.WriteLine();
                eq3.EquationOutput();

                Console.WriteLine($"x = {x1}, y = {x2}, z = {x3}");
            }
            else
            {
                Console.WriteLine("Try again!");
            }
        }
 /// <summary>
 /// Returns a new <see cref="ImmutableMatrix2x2" /> which is the product of this and another <see cref="ImmutableMatrix2x2" />
 /// </summary>
 public ImmutableMatrix2x2 Multiply(IMatrix2x2 right)
 {
     return(new ImmutableMatrix2x2(base.MultiplyBase(this, right)));
 }
Пример #6
0
 /// <summary>
 /// Returns a new <see cref="Matrix2x2" /> which is the product of this and another <see cref="Matrix2x2" /> to the right.
 /// </summary>
 public Matrix2x2 MultiplyRight(IMatrix2x2 right)
 {
     _underlyingValues.Update(base.MultiplyBase(this, right));
     return(this);
 }
Пример #7
0
 /// <summary>
 /// Returns a new <see cref="Matrix2x2" /> which is the product of this and another <see cref="Matrix2x2" /> to the left.
 /// </summary>
 public Matrix2x2 MultiplyLeft(IMatrix2x2 left)
 {
     _underlyingValues.Update(base.MultiplyBase(left, this));
     return(this);
 }