//получение собственных значений матрицы private static double[] GetEigenValues(double[] p, int numberOfRoots) { //по формуле, при построении полинома знаки коэфициентов около всех степеней, кроме старшей, меняются var SignChangedCoefs = p.Select(v => - v).ToList(); //добавляем 1 для старшей степени SignChangedCoefs.Insert(0, 1); //return EquationSolver.GetRoots(SignChangedCoefs.ToArray(), 0.00000001, 0.1); return(EquationSolver.GetRoots(SignChangedCoefs.ToArray(), numberOfRoots)); }
public void GetRoots_TwoZeroCoefficients_Return1Root() { //arrange double determinant = 0; double[] coefficients = new[] { 2.0, 0, 0 }; EquationSolver equationSolver = new EquationSolver(); //act double[] roots = equationSolver.GetRoots(determinant, coefficients); //assert Assert.AreEqual(new[] { 0, 0 }, roots); }
public void GetRoots_ThreeNegativeCoefficients_Return2Roots() { //arrange double determinant = 1; double[] coefficients = new[] { -4.0, -9, -5 }; EquationSolver equationSolver = new EquationSolver(); //act double[] roots = equationSolver.GetRoots(determinant, coefficients); //assert Assert.AreEqual(new[] { -1.25, -1 }, roots); }
public void GetRoots_OneZeroCoefficient_Return2Roots() { //arrange double determinant = 25; double[] coefficients = new[] { 2.0, 5, 0 }; EquationSolver equationSolver = new EquationSolver(); //act double[] roots = equationSolver.GetRoots(determinant, coefficients); //assert Assert.AreEqual(new[] { 0, -2.5 }, roots); }
public void GetRoots_ThreePositiveCoefficients_Return2Roots() { //arrange double determinant = 9; double[] coefficients = new[] { 2.0, 5, 2 }; EquationSolver equationSolver = new EquationSolver(); //act double[] roots = equationSolver.GetRoots(determinant, coefficients); //assert Assert.AreEqual(new[] { -0.5, -2 }, roots); }