Esempio n. 1
0
        public static Matrix Step(Matrix matrix)
        {
            var elements = matrix.Elements;

            for (var i = 0; i < matrix.Height; i++)
            {
                for (var j = 0; j < matrix.Width; j++)
                {
                    if (i != j)
                    {
                        continue;
                    }
                    if (elements[i][j] == new Fraction(0))
                    {
                        var end = true;
                        for (var k = i + 1; k < matrix.Height; k++)
                        {
                            if (elements[k][j] == new Fraction(0))
                            {
                                continue;
                            }
                            var b = new Fraction[matrix.Width];
                            for (var l = 0; l < matrix.Width; l++)
                            {
                                b[l] = elements[i][l];
                            }
                            for (var l = 0; l < matrix.Width; l++)
                            {
                                elements[i][l] = elements[k][l];
                            }
                            for (var l = 0; l < matrix.Width; l++)
                            {
                                elements[k][l] = b[l];
                            }
                            end = false;
                            break;
                        }
                        if (end)
                        {
                            break;
                        }
                    }
                    var t = elements[i][j];
                    for (var n = 0; n < matrix.Width; n++)
                    {
                        elements[i][n] = elements[i][n] / t;
                    }
                    for (var m = 0; m < matrix.Height; m++)
                    {
                        if (m == i || elements[m][j] == new Fraction(0))
                        {
                            continue;
                        }
                        var u = elements[m][j];
                        for (var n = 0; n < matrix.Width; n++)
                        {
                            elements[m][n] -= elements[i][n] * u;
                        }
                    }
                }
            }
            return(matrix);
        }
Esempio n. 2
0
        public static Matrix operator *(int a, Matrix b)
        {
            var c = new Fraction(a);

            return(c * b);
        }