Пример #1
0
        public string ImBasis()
        {
            MyMatrix    row_echelon = Clone();
            string      output      = row_echelon.GaussLaTeX(revert: false) + '\n';
            LaTeXExport export      = new LaTeXExport(1, ",", 1, false, "$$\\text{Im basis}:\\ ");

            for (int i = 0; i < n; i++)
            {
                int j_s = 0;
                for (; j_s < m && row_echelon[i, j_s] == 0; j_s++)
                {
                    ;
                }
                if (j_s >= m)
                {
                    break;
                }
                export.Add(GetColumn(j_s).GetLaTeX());
            }
            if (export.Empty)
            {
                export.Add(GetColumn(0).GetLaTeX());
            }
            return(output + export.Result);
        }
Пример #2
0
        public string KerBasis()
        {
            MyMatrix    row_echelon = Clone();
            string      output      = row_echelon.GaussLaTeX() + '\n';
            LaTeXExport export      = new LaTeXExport(1, ",", 1, false, "$$\\ker\\ \\text{basis}:\\ ");
            List <int>  pivots      = new List <int>();

            for (int i = 0; i < n; i++)
            {
                int j_s = 0;
                for (; j_s < m && row_echelon[i, j_s] == 0; j_s++)
                {
                    ;
                }
                if (j_s >= m)
                {
                    break;
                }
                pivots.Add(j_s);
            }
            int j_free = 0;

            for (int j = 0; j < m - pivots.Count; j++, j_free++)
            {
                for (; pivots.Contains(j_free); j_free++)
                {
                    ;
                }
                MyMatrix basis_el = new MyMatrix(m, 1);
                basis_el[j_free, 0] = 1;
                for (int i = 0; i < pivots.Count; i++)
                {
                    basis_el[pivots[i], 0] = -row_echelon[i, j_free];
                }
                export.Add(basis_el.GetLaTeX());
            }
            if (export.Empty)
            {
                export.Add(new MyMatrix(m, 1).GetLaTeX());
            }
            return(output + export.Result);
        }
Пример #3
0
        public string InverseLaTeX()
        {
            if (!IsSquare)
            {
                throw new InvalidOperationException("Matrix is not square!");
            }
            if (Determinant == 0)
            {
                throw new DivideByZeroException("Determinant zero!");
            }
            MyMatrix tmp = new MyMatrix(n, n * 2);

            tmp.Set(this);
            for (int i = 0; i < n; i++)
            {
                tmp[i, i + n] = 1;
            }
            string output = tmp.GaussLaTeX(n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    tmp[i, j] = tmp[i, j + n];
                }
            }
            tmp.M = n;

            /*try
             * {
             *  if (!(tmp * this).Equals(Id))
             *      throw new Exception();
             * }
             * catch { throw new ArithmeticException("Cannot find inverse matrix!"); }*/
            values = tmp.values;
            return(output);
        }