示例#1
0
        public static Tuple <List <double>, Matrix, string> Solve(Matrix a)
        {
            double[][] y  = new double[a.RowsCount][];
            double[]   y0 = new double[a.RowsCount];
            y0[0] = 1;
            double[] yv = (double[])y0.Clone();
            for (int i = 0; i < a.RowsCount; i++)
            {
                y[i] = a * yv;
                yv   = y[i];
            }
            for (int i = 0; i < y.Length; i++)
            {
                for (int j = 0; j < y[i].Length; j++)
                {
                    y[i][j] *= -1;
                }
            }
            Matrix A = new Matrix(a.RowsCount, 0);

            for (int i = a.RowsCount - 2; i >= 0; i--)
            {
                A.AddColumn(y[i]);
            }
            y0[0] = -1;
            A.AddColumn(y0);
            double[] b = new double[a.RowsCount];
            b = y[a.RowsCount - 1];
            double[]      p     = GaussMainElement.Solve(A.GetElements(), b);
            List <double> roots = new CharactericEqual(p.ToList()).GetRoots();

            Matrix q = Utils.GetOwnVectors(a, roots.ToArray());

            return(new Tuple <List <double>, Matrix, string>(roots, q, null));
        }
示例#2
0
        public static Matrix GetOwnVectors(Matrix a, double[] ownValues)
        {
            int    n    = a.RowsCount;
            Matrix Q    = new Matrix(n);
            Matrix temp = null;

            double[] ov;
            double[] bn;
            for (int i = 0; i < n; i++)
            {
                temp = a.Copy();
                temp.RemoveRow(n - 1);
                for (int k = 0; k < n - 1; k++)
                {
                    temp[k][k] -= ownValues[i];
                }
                ov = new double[n - 1];
                bn = new double[n - 1];
                for (int k = 0; k < bn.Length; k++)
                {
                    bn[k] = -temp[k][n - 1];
                }
                temp.RemoveColumn(n - 1);

                double[] res = (GaussMainElement.Solve(temp.GetElements(), bn));
                for (int j = 0; j < n - 1; j++)
                {
                    Q[j][i] = res[j];
                }
                Q[n - 1][i] = 1;
            }
            return(Q);
        }