private void BtnSimpson_Click(object sender, EventArgs e) { Simpson simpson = new Simpson(); simpson.Show(); this.Hide(); }
private void begin_Click(object sender, EventArgs e) { EnabledControls(true); relativeMajority = new RelativeMajority((int)alternatives_count.Value); clearWinner = new ClearWinner(); kopland = new Kopland(); simpson = new Simpson(); board = new Board(); for (int i = 0; i < (int)experts_count.Value; i++) { Expert expert = new Expert("Эксперт " + (i + 1), (int)alternatives_count.Value); experts.Add(expert); } relativeMajority.Experts = experts; current_expert_name.Text = experts[0].Name; for (int i = 0; i < (int)alternatives_count.Value; i++) { alternatives.Items.Add("Альтернатива " + (i + 1)); relative_majority_dgv.Rows.Add(alternatives.Items[i].ToString(), "0", "0,00"); } for (int i = 0; i < dgvs.Length; i++) { for (int j = 0; j < (int)experts_count.Value; j++) { dgvs[i].Columns.Add("expert" + j, "Эксперт " + (j + 1)); } dgvs[i].Rows.Add((int)alternatives_count.Value); } }
public void TestSimpsonsRule(int expected) { Simpson si = new Simpson(); int actual = Simpson.SimpsonRule(); Assert.AreEqual(actual, expected); }
public void TestSimposon(int n, int min, int max, int actual) { Simpson simpson = new Simpson(); double expected = simpson.areaApprox(n, min, max); Assert.AreEqual(expected, actual); }
static void Main(string[] args) { Medios A = new Medios(); Trapezios B = new Trapezios(); Simpson C = new Simpson(); Console.ReadKey(); }
public void S_xx_10_0() { //arrange double expected = -333.333; double a = 10; double b = 0; int n = 10000; ICalculator calcul = new Simpson(); //act double actual = calcul.Calculate(a, b, n, x => x * x); //assert Assert.AreEqual(expected, actual, 0.001); }
public void S_Step_0() { //arrange double expected = 0; double a = 10; double b = 10; int n = 10000; ICalculator calcul = new Simpson(); //act double actual = calcul.CalculateParallel(a, b, n, x => x * x); //assert Assert.AreEqual(expected, actual); }
public void S_xx_Odd_Step() { //arrange double expected = 333.333; double a = 0; double b = 10; int n = 1001; ICalculator calcul = new Simpson(); //act double actual = calcul.CalculateParallel(a, b, n, x => x * x); //assert Assert.AreEqual(expected, actual, 0.001); }
public ActionResult Simpson() { Simpson_Model model = new Simpson_Model(); model.function = "sin(x)"; model.a = 0; model.b = 3.1416; model.n = 20; Simpson resultado = new Simpson(); model.ans = new Answer_Model(); model.ans.Res = resultado.Calcular(model.function, model.a, model.b, model.n); return(View(model)); }
public void Simpson_Integrate_with_switched_variables() { //arrange double expected = -333_333.3333; double a = 100; double b = 0; long n = 100000; Simpson simpson = new Simpson(); Func <double, double> f = x => x * x; //act double actual = simpson.Calculate(a, b, n, f); //assert Assert.AreEqual(expected, actual, 0.0001); }
public void Simpson_Intergrate_xx_Gives_Correct_Result() { //arrange double expected = 333_333.3333; double a = 0; double b = 100; long n = 100000; Simpson simpson = new Simpson(); Func <double, double> f = x => x * x; //act double actual = simpson.Calculate(a, b, n, f); //assert Assert.AreEqual(expected, actual, 0.0001); }
public ActionResult Simpson(Simpson_Model model) { Simpson resultado = new Simpson(); model.ans = new Answer_Model(); model.ans.Res = resultado.Calcular(model.function, model.a, model.b, model.n); if (model.ans.Res[0] == 'L') { model.ans.status = 1; } else { model.ans.status = 2; } return(View(model)); }
public void TestSimpsonMethod() { int alternatinves = 3; Simpson simpson = new Simpson(); List <Expert> experts = new List <Expert>(); Expert expert1 = new Expert("Эксперт 1", alternatinves); Expert expert2 = new Expert("Эксперт 2", alternatinves); Expert expert3 = new Expert("Эксперт 3", alternatinves); Expert expert4 = new Expert("Эксперт 4", alternatinves); Expert expert5 = new Expert("Эксперт 5", alternatinves); Expert expert6 = new Expert("Эксперт 6", alternatinves); expert1.Preferences = new int[] { 1, 2, 3 }; expert2.Preferences = new int[] { 2, 3, 1 }; expert3.Preferences = new int[] { 3, 2, 1 }; expert4.Preferences = new int[] { 1, 2, 3 }; expert5.Preferences = new int[] { 1, 3, 2 }; expert6.Preferences = new int[] { 1, 2, 3 }; experts.AddRange(new Expert[] { expert1, expert2, expert3, expert4, expert5, expert6 }); simpson.Experts = experts; Assert.AreEqual("Альтернатива 1", simpson.Execute()); }
private void ButtonOK_Click(object sender, EventArgs e) { try { textBox1.Text = textBox1.Text.Replace('.', ','); textBox2.Text = textBox2.Text.Replace('.', ','); int countIntervals = int.Parse(textBoxCountIntervals.Text); double[] array = new double[formMain.network.CountNeurons]; switch (comboBoxDistribution.SelectedItem.ToString()) { case "Арксинус": { array = new Arcsinus(Double.Parse(textBox1.Text), Int32.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Arcsinus", true, countIntervals); CloseForm(); break; } case "Экспоненциальное": { array = new ExponentialOneway(Double.Parse(textBox1.Text), Int32.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Exponential", true, countIntervals); CloseForm(); break; } case "Лаплас": { array = new Laplas(Double.Parse(textBox1.Text), Double.Parse(textBox2.Text), Int32.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Laplas", true, countIntervals); CloseForm(); break; } case "Нормальное": { array = new Normal(Double.Parse(textBox1.Text), Double.Parse(textBox2.Text), Int32.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Normal", true, countIntervals); CloseForm(); break; } case "Релей": { array = new Relei(Double.Parse(textBox1.Text), Int32.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Relei", true, countIntervals); CloseForm(); break; } case "Симпсон": { array = new Simpson(Double.Parse(textBox1.Text), Double.Parse(textBox2.Text), Int32.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Simpson", true, countIntervals); CloseForm(); break; } case "Коши": { array = new Koshi(Double.Parse(textBox1.Text), Double.Parse(textBox2.Text), int.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Koshi", true, countIntervals); CloseForm(); break; } case "Равномерный": { array = new Uniform(Double.Parse(textBox1.Text), Double.Parse(textBox2.Text), int.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Uniform", true, countIntervals); CloseForm(); break; } case "Вейбулл": { array = new Veibull(Double.Parse(textBox1.Text), Double.Parse(textBox2.Text), int.Parse(textBoxCount.Text)).Generate(); formMain.Generate(array, "Veibul", true, countIntervals); CloseForm(); break; } } } catch { MessageBox.Show("Проверьте правильность введенных данных"); } }
public void ExecuteMethod( string nameMethod, double param1, double param2, double param3, double param4, string testFunction, int rangeArray, double[] LinSysMasA, double[,] LinSysMatrixB, double[] massX, double[] massF, double[] massW, double pointInterpolation, double[,] MatrixAlgebraA, double pointPercentile, double pointGenerator) { TestFunction = testFunction; switch (nameMethod) { //*** Approximate decision of equalization f(x)=0 *** case "Bisection Method": { Bisection bisect = new Bisection(new FunctionOne(TestFunBisection), param1, param2, param3); result = "\n Result of the program: \n" + " x= " + string.Format("{0:f" + precision + "}", bisect.Result); } break; case "Chord Method": { Сhord chord = new Сhord(new FunctionOne(TestFunNewton), new FunctionOne(TestFunNewton2), param1, param2, param3, param4); result = "\n Result of the program: \n" + " x= " + string.Format("{0:f" + precision + "}", chord.GetSolution()); } break; case "Iteration Method": { IterationMethod itermet = new IterationMethod(new FunctionOne(TestFunIteration), param1, param2, param3, param4); result = "\n Result of the program: \n" + " x= " + string.Format("{0:f" + precision + "}", itermet.GetSolution()); } break; case "Newton Method": { Newton newton = new Newton(new FunctionOne(TestFunNewton), new FunctionOne(TestFunNewton2), param1, param2, param3, param4); result = "\n Result of the program: \n" + " x= " + string.Format("{0:f" + precision + "}", newton.GetSolution()); } break; //*** Differential Equations *** case "Euler Simple": { EulerSimple eulersimpl = new EulerSimple(new Function(TestFunDifferEquations), param1, param2, param3, Convert.ToInt32(param4)); var result_eulersimpl = eulersimpl.Result; for (int j = 0; j < Convert.ToInt32(param4); j++) { result = result + string.Format("{0:f" + precision + "}", result_eulersimpl[0, j]) + " : " + string.Format("{0:f" + precision + "}", result_eulersimpl[1, j]) + "\n"; } } break; case "Euler Modified": { EulerModified eulerModif = new EulerModified(new Function(TestFunDifferEquations), param1, param2, param3, Convert.ToInt32(param4)); var result_eulerModif = eulerModif.Result; for (int j = 0; j < Convert.ToInt32(param4); j++) { result = result + string.Format("{0:f" + precision + "}", result_eulerModif[0, j]) + " : " + string.Format("{0:f" + precision + "}", result_eulerModif[1, j]) + "\n"; // result = result + "fun=\n"; // result = result +Convert.ToString( TestFunDifferEquations); } } break; case "Euler Corrected": { EulerCorrected eulerCorrect = new EulerCorrected(new Function(TestFunDifferEquations), param1, param2, param3, Convert.ToInt32(param4)); var result_eulerCorrect = eulerCorrect.Result; for (int j = 0; j < Convert.ToInt32(param4); j++) { result = result + string.Format("{0:f" + precision + "}", result_eulerCorrect[0, j]) + " : " + string.Format("{0:f" + precision + "}", result_eulerCorrect[1, j]) + "\n"; } } break; case "Runge-Kutta4": { RungeKutta4 rungeKutta4 = new RungeKutta4(new Function(TestFunDifferEquations), param1, param2, param3, Convert.ToInt32(param4)); var result_rungeKutta4 = rungeKutta4.Result; for (int j = 0; j < Convert.ToInt32(param4); j++) { result = result + string.Format("{0:f" + precision + "}", result_rungeKutta4[0, j]) + " : " + string.Format("{0:f" + precision + "}", result_rungeKutta4[1, j]) + "\n"; } } break; //*** Integration *** case "Chebishev": Chebishev chebish = new Chebishev(new FunctionOne(TestFunInteger), param1, param2, Convert.ToInt32(param3)); var result_chebish = chebish.GetSolution(); for (int j = 0; j <= Convert.ToInt32(param3); j++) { result = result + "\n h = " + string.Format("{0:f" + precision + "}", result_chebish[1, j]) + " \t integral = " + string.Format("{0:f" + precision + "}", result_chebish[0, j]); } break; case "Simpson": Simpson simps = new Simpson(new FunctionOne(TestFunInteger), param1, param2, Convert.ToInt32(param3)); var result_simps = simps.GetSolution(); for (int j = 0; j <= Convert.ToInt32(param3); j++) { result = result + "\n h = " + string.Format("{0:f" + precision + "}", result_simps[1, j]) + " \t integral = " + string.Format("{0:f" + precision + "}", result_simps[0, j]); } break; case "Simpson2": Simpson2 simps2 = new Simpson2(new FunctionOne(TestFunInteger), param1, param2, Convert.ToInt32(param3)); var result_simps2 = simps2.GetSolution(); result = "\n\n integral = " + string.Format("{0:f" + precision + "}", result_simps2); break; case "Trapezium": Trapezium trapez = new Trapezium(new FunctionOne(TestFunInteger), param1, param2, Convert.ToInt32(param3)); var result_trapez = trapez.GetSolution(); for (int j = 0; j <= Convert.ToInt32(param3); j++) { result = result + "\n h = " + string.Format("{0:f" + precision + "}", result_trapez[1, j]) + " \t integral = " + string.Format("{0:f" + precision + "}", result_trapez[0, j]); } break; //*** Non Linear equalization *** case "Half Division": HalfDivision halfdiv = new HalfDivision(new FunctionOne(TestFunNonLinearEquations), param1, param2, param3); result = "\n X = " + string.Format("{0:f" + precision + "}", halfdiv.GetSolution()[0, 0]) + " Iterations = " + string.Format("{0:f" + precision + "}", halfdiv.GetSolution()[1, 0]); break; case "Hord Metod": HordMetod hormet = new HordMetod(new FunctionOne(TestFunNonLinearEquations), param1, param2, Convert.ToInt32(param3)); result = "\n X = " + string.Format("{0:f" + precision + "}", hormet.GetSolution()[0, 0]) + " Iterations = " + string.Format("{0:f" + precision + "}", hormet.GetSolution()[1, 0]); break; case "Newton Metod": NewtonMethod newt = new NewtonMethod(new FunctionOne(TestFunNonLinearEquations), param1, param2); result = "\n X = " + string.Format("{0:f" + precision + "}", newt.GetSolution()[0, 0]) + " Iterations = " + string.Format("{0:f" + precision + "}", newt.GetSolution()[1, 0]); break; case "Secant Metod": Secant sec = new Secant(new FunctionOne(TestFunNonLinearEquations), param1, param2); result = "\n X = " + string.Format("{0:f" + precision + "}", sec.GetSolution()[0, 0]) + " Iterations = " + string.Format("{0:f" + precision + "}", sec.GetSolution()[1, 0]); break; default: result = ""; break; //*** Linear Systems *** case "Gaus": double[,] LinSysMatrix; LinSysMatrix = new double[100, 100]; for (int l = 0; l < rangeArray; l++) { for (int j = 0; j < rangeArray; j++) { LinSysMatrix[l, j] = LinSysMatrixB[l, j]; } LinSysMatrix[l, rangeArray] = LinSysMasA[l]; } Gaus gaus = new Gaus(4, LinSysMatrix); var result_gaus = gaus.GetSolution(); result = ""; for (int j = 0; j < result_gaus.Length; j++) { result = result + "\n X" + j + " = " + string.Format("{0:f" + precision + "}", result_gaus[j]) + ";"; } break; case "Zeidel": Zeidel zeidel = new Zeidel(4, LinSysMatrixB, LinSysMasA); var result_zeidel = zeidel.GetSolution(); result = ""; for (int j = 0; j < result_zeidel.Length; j++) { result = result + "\n X" + j + " = " + string.Format("{0:f" + precision + "}", result_zeidel[j]) + ";"; } break; //*** Interpolation *** case "Lagrange Interpolator": LagrangeInterpolator lagran = new LagrangeInterpolator(massX, massF, 6, pointInterpolation); result = "\n A value interpolation polynomial is in the point of interpolation."; result = result + "\n\n P = " + string.Format("{0:f" + precision + "}", lagran.GetSolution()); break; case "Newton Interpolator": NewtonInterpolator newinterpol = new NewtonInterpolator(massX, massF, 6, pointInterpolation); result = "\n A value interpolation polynomial is in the point of interpolation."; result = result + "\n\n P = " + string.Format("{0:f" + precision + "}", newinterpol.GetSolution()); break; case "Neville Interpolator": NevilleInterpolator newill = new NevilleInterpolator(massX, massF, 6, pointInterpolation); result = "\n A value interpolation polynomial is in the point of interpolation."; result = result + "\n\n P = " + string.Format("{0:f" + precision + "}", newill.GetSolution()); break; case "Spline Interpolator": SplineInterpolator spline = new SplineInterpolator(massX, massF, 6, pointInterpolation); result = "\n A value interpolation polynomial is in the point of interpolation."; result = result + "\n\n P = " + string.Format("{0:f" + precision + "}", spline.GetSolution()); break; case "Barycentric Interpolator": BarycentricInterpolation barycen = new BarycentricInterpolation(massX, massF, massW, 6, pointInterpolation); result = "\n A value interpolation polynomial is in the point of interpolation."; result = result + "\n\n P = " + string.Format("{0:f" + precision + "}", barycen.GetSolution()); break; //*** Matrix Algebra *** case "Matrix Determinant": MatrixDeterminant matrdet = new MatrixDeterminant(); result = " \n\n\n Determinant = " + string.Format("{0:f" + precision + "}", matrdet.MatrixDet(MatrixAlgebraA, rangeArray)) + ";\n"; break; case "RMatrix LU": MatrixLU matrlu = new MatrixLU(MatrixAlgebraA, rangeArray, rangeArray); var result_matrlu = matrlu.GetSolution(); var result_matrlu2 = matrlu.GetSolution2(); result = "A:\n"; for (int ii = 0; ii < rangeArray; ii++) { for (int j = 0; j < rangeArray; j++) { result = result + " \t " + string.Format("{0:f" + precision + "}", result_matrlu[ii, j]); } result = result + " \n"; } result = result + "\nL:\n"; for (int ii = 0; ii < rangeArray; ii++) { result = result + " " + string.Format("{0:f" + precision + "}", result_matrlu2[ii]); } result = result + " \n "; break; case "Matrix Inverse LU": RMatrixLuInverse matrluinv = new RMatrixLuInverse(); MatrixLU matrlu2 = new MatrixLU(MatrixAlgebraA, rangeArray, rangeArray); if (matrluinv.rmatrixluinverse(MatrixAlgebraA, rangeArray, matrlu2.GetSolution2()) == true) { result = "\n An inverse matrix exists \n\n "; var result_matrluinv = matrluinv.GetSolution(); for (int ii = 0; ii < rangeArray; ii++) { for (int j = 0; j < rangeArray; j++) { result = result + " \t" + string.Format("{0:f" + precision + "}", result_matrluinv[ii, j]); } result = result + "\n\n"; } } else { result = "\n An inverse matrix does not exist"; } break; //*** Optimizing*** case "Brentopt": Brentopt brent = new Brentopt(new FunctionOne(TestFunOptimizing), param1, param2, param3); result = "\n Point of the found minimum :"; result = result + "\n\n XMin = " + string.Format("{0:f" + precision + "}", brent.GetSolution()); result = result + "\n\n A value of function is in the found minimum :"; result = result + "\n\n F(XMin) = " + string.Format("{0:f" + precision + "}", brent.GetSolutionFunction()); break; case "Golden Section": GoldenSection godsection = new GoldenSection(new FunctionOne(TestFunOptimizing), param1, param2, Convert.ToInt32(param3)); result = "\n Scopes of segment which a decision of task is on ."; result = result + "\n\n a = " + string.Format("{0:f" + precision + "}", godsection.GetSolutionA()); result = result + "\n\n b = " + string.Format("{0:f" + precision + "}", godsection.GetSolutionB()); break; case "Pijavsky": Pijavsky pijavsky = new Pijavsky(new FunctionOne(TestFunOptimizing), param1, param2, param3, Convert.ToInt32(param4)); result = "\n Abscissa of the best point from found.."; result = result + "\n\n F = " + string.Format("{0:f" + precision + "}", pijavsky.GetSolution()); break; //*** Statistics *** case "Correlation Pearson": CorrelationPearson corelperson = new CorrelationPearson(massX, massF, 6); result = "\n Pearson product-moment correlation coefficient."; result = result + "\n\n K = " + string.Format("{0:f" + precision + "}", corelperson.GetSolution()); break; case "Correlation Spearmans Rank": CorrelationSpearmansRank corelspear = new CorrelationSpearmansRank(massX, massF, 6); result = "\n Pearson product-moment correlation coefficient."; result = result + "\n\n K = " + string.Format("{0:f" + precision + "}", corelspear.GetSolution()); break; case "Descriptive Statistics Median": DescriptiveStatisticsADevMedian desceripM = new DescriptiveStatisticsADevMedian(massX, 6); result = "\n Output parameters:"; result = result + "\n\n M = " + string.Format("{0:f" + precision + "}", desceripM.GetSolution()); break; case "Descriptive Statistics Moments": DescriptiveStatisticsMoments desceripMo = new DescriptiveStatisticsMoments(massX, 6); result = "\n Output parameters:"; result = result + "\n\n M = " + string.Format("{0:f" + precision + "}", desceripMo.GetSolution()); result = result + "\n\n Variance = " + string.Format("{0:f" + precision + "}", desceripMo.variance); result = result + "\n\n Skewness = " + string.Format("{0:f" + precision + "}", desceripMo.skewness) + " (if variance<>0; zero otherwise)"; result = result + "\n\n Kurtosis = " + string.Format("{0:f" + precision + "}", desceripMo.kurtosis) + " (if variance<>0; zero otherwise)"; break; case "Descriptive Statistics Percentile": DescriptiveStatisticsPercentile desceripP = new DescriptiveStatisticsPercentile(massX, 6, pointPercentile); result = "\n Output parameters:"; result = result + "\n\n V = " + string.Format("{0:f" + precision + "}", desceripP.GetSolution()); break; case "Generator 1": RandomGeneratorsMethod1 random1 = new RandomGeneratorsMethod1(); result = "\n Output parameters:"; result = result + "\n\n Random = " + string.Format("{0:f" + precision + "}", random1.GetSolution()); break; case "Generator 2": RandomGeneratorsMethod2 random2 = new RandomGeneratorsMethod2(Convert.ToInt32(pointGenerator)); result = "\n Output parameters:"; result = result + "\n\n Random = " + string.Format("{0:f" + precision + "}", random2.GetSolution()); break; case "Generator 3": RandomGeneratorsMethod3 random3 = new RandomGeneratorsMethod3(); result = "\n Output parameters:"; result = result + "\n\n Random = " + string.Format("{0:f" + precision + "}", random3.GetSolution()); break; case "Generator 4": RandomGeneratorsMethod4 random4 = new RandomGeneratorsMethod4(); result = "\n Output parameters:"; result = result + "\n\n Random = " + string.Format("{0:f" + precision + "}", random4.GetSolution()); break; case "Generator 5": RandomGeneratorsMethod5 random5 = new RandomGeneratorsMethod5(pointGenerator); result = "\n Output parameters:"; result = result + "\n\n Random = " + string.Format("{0:f" + precision + "}", random5.GetSolution()); break; } }
static void Main(string[] args) { string line = Environment.NewLine; { Console.WriteLine("Linked List"); Console.WriteLine(line); MyLinkedList <string> LList = new MyLinkedList <string>(); LList.Add("dashulya"); LList.Add("Deniska"); foreach (string s in LList) { Console.WriteLine(s); } Console.WriteLine($"Llist contains dashulya: {LList.contains("dashulya")}"); Console.WriteLine($"Llist contains Dens: {LList.contains("Dens")}"); Console.WriteLine(line); } { Console.WriteLine("Fast Pow"); Console.WriteLine(line); for (int i = 0; i < 5; i++) { Console.WriteLine($"{i} in {i * 2} ={Pow.Recursive(i, i * 2)}"); Console.WriteLine($"{i} in {i + 2} ={Pow.Iter(i, i + 2)}"); Console.WriteLine($"{i} in {15} ={Pow.Byte(i, 15)}"); } Console.WriteLine(line); } { Console.WriteLine("Levenstain distance"); Console.WriteLine(line); Console.Write("Enter First word"); var s1 = Console.ReadLine(); Console.Write("Enter Second word"); var s2 = Console.ReadLine(); Console.WriteLine($"Расстояние Левенштейна для слов {s1} и {s2} равно {Levenstain_Distance.Find(s1, s2)}"); Console.WriteLine($"Расстояние Левенштейна для слов {s1} и {s2} равно {Levenstain_Distance.Find(s1, s2, true)}"); Console.WriteLine(line); } { Console.WriteLine("Sorts"); Console.WriteLine(line); Console.WriteLine("Sorted array: {0}", string.Join(", ", RandomSort.Sort(numbersArr))); //Can`t work with big range List <ISort> Sorts = new List <ISort>() { new BubbleSort(), new CocktailSort(), new CombSort(), new CountingSort(), new GnomeSort(), new InsertionSort(), new MergeSort(), new PancakeSort(), new QuickSort(), new SelectionSort(), new ShellSort(), new StoogeSort(), new TreeSort() }; SortStarter.Start(Sorts); Console.WriteLine(line); } RandomInt32Array rnd = new RandomInt32Array(50, -10, 25); var TestArr = rnd.Array; Console.WriteLine("Search"); Console.WriteLine(line); Console.WriteLine("Maximum ind: " + TestArr.IndOfMaximum()); Console.WriteLine("Minimum ind: " + TestArr.IndOfMinimum()); Console.WriteLine("Maximum: " + TestArr.MaximumVal()); Console.WriteLine("Minimum: " + TestArr.MinimumVal()); Console.WriteLine(line); QuickSort QS = new QuickSort(); TestArr = QS.Sort(TestArr); Console.WriteLine("TestArray 5 index " + BinarySearch.BinSearch(TestArr, 5, 0, TestArr.Length - 1)); Console.WriteLine(line); Console.WriteLine("Поиск длиннейшей общей подстроки. Введите два слова ниже"); Console.WriteLine("Общая подстрока: " + LongestComonString.Search(Console.ReadLine(), Console.ReadLine()) + line); Console.WriteLine("Граф. Поиск кратчайшего пути."); var g = DikstraHelper.CreateGraph(); var D = new DiikstraAlgoritm(g); var path = D.FindShortestPath("A", "D"); Console.WriteLine(path); Console.WriteLine(line); double f(double x) => (x * 5 - 1) / 5; var simpRes = Simpson.Integral(f, 0, 10, 1000); Console.WriteLine($"Интеграл функции х^5 от 0 до 10 равен {simpRes}" + line);; Console.ReadLine(); }
//&i static void Main(string[] args) { // Atributos double dX = 0; double dE = 0.000000001; // Error int iDof = 0; // Grados de libertad double dP = 0; // added // Obtener dP String sInput = Console.ReadLine(); try { dP = Double.Parse(sInput); //&m } catch (Exception) { Console.WriteLine("Error en el dato introducido"); Console.ReadLine(); Environment.Exit(0); } if (dP < 0 || dP > 0.5) //&m { Console.WriteLine("Error en el dato introducido"); Console.ReadLine(); Environment.Exit(0); } // Obtener iDof sInput = Console.ReadLine(); try { iDof = int.Parse(sInput); } catch (Exception) { Console.WriteLine("Error en el dato introducido"); Console.ReadLine(); Environment.Exit(0); } if (iDof <= 0) { Console.WriteLine("Error en el dato introducido"); Console.ReadLine(); Environment.Exit(0); } // Numero de segmentos por default = 10 int iNum_Seg = 1000; //&d=9 dX = 1; // test simpson Simpson simpsonT = new Simpson(dX, iDof, iNum_Seg); double CorrigeX = simpsonT.calcularP() - dP; double correccion = 0.5; char changesimbol = '-'; // p = positive, n = negative if (simpsonT.calcularP() != dP) { if (CorrigeX > 0) { dX -= correccion; changesimbol = 'p'; } else if (CorrigeX < 0) { dX += correccion; changesimbol = 'n'; } simpsonT = new Simpson(dX, iDof, iNum_Seg); CorrigeX = simpsonT.calcularP() - dP; } while (Math.Abs(CorrigeX) > dE) { if (CorrigeX > 0) { if (changesimbol == 'n') { correccion /= 2; changesimbol = 'p'; } dX -= correccion; } else if (CorrigeX < 0) { if (changesimbol == 'p') { correccion /= 2; changesimbol = 'n'; } dX += correccion; } simpsonT = new Simpson(dX, iDof, iNum_Seg); CorrigeX = simpsonT.calcularP() - dP; } // Print Console.WriteLine("P = " + string.Format("{0:N5}", dP)); //&m Console.WriteLine("dof = " + iDof); Console.WriteLine("x = " + string.Format("{0:N5}", Math.Round(dX, 5))); //&m Console.ReadLine(); }