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)); }
public void Calculate() { List <double> roots = new CharactericEqual(P.ToList()).GetRoots(); Lambda = roots.Select(e => Math.Round(e, 2)).ToArray(); Matrix a = new Matrix(A); OwnMatrix = Utils.GetOwnVectors(a, roots.ToArray()); //MessageBox.Show(q.ToString()); //List<double[]> es = new List<double[]>(); //double[][] at; //string s = ""; //foreach (var i in Lambda) // s += i + " "; //s += "\n\n"; //Gauss ga; //for (int k = 0; k < N; k++) //{ // InitArray(out at, Lambda[k]); // for (int i = 0; i < N; i++) // { // for (int j = 0; j < N; j++) // s += at[i][j] + " "; // s += "\n"; // } // s += "\n\n"; // ga = new Gauss(N); // ga.A = at; // ga.B = new double[] { 1, 0, 0 }; // double[] res = ga.Calculate().Select(e => Math.Round(e, 2)).ToArray(); // MessageBox.Show(res[0] + " " + res[1] + " " + res[2]); // es.Add(res); //} //for (int i = 0; i < N; i++) //{ // for (int j = 0; j < N; j++) // s += es[j][i] + " "; // s += "\n"; //} //MessageBox.Show(s); }