/// <summary> /// Returns the normal water level for a canal section given a flow /// </summary> /// <param name="flow">The flow through the canal section</param> /// <returns></returns> public double GetNormalWaterLevel(double flow) { Func <double, double> equation = (x) => GetManningFlow(x) - flow; NewtonRaphson newtonRaphson = new NewtonRaphson(equation); return(newtonRaphson.Solve(GetCriticalWaterLevel(flow), 0.009)); }
public void BasicEquationNoDerivativeSolve() { double epsilon = 0.0001; NewtonRaphson newtonRaphson = new NewtonRaphson((x => x + 5)); double result = newtonRaphson.Solve(0, epsilon); Assert.IsTrue(Math.Abs(-5 - result) < epsilon); }
public void SecondDegreeEquationNoDerivativeSolve2() { double epsilon = 0.0001; NewtonRaphson newtonRaphson = new NewtonRaphson((x => x * x - x - 2)); double result = newtonRaphson.Solve(10, epsilon); double error = Math.Abs(2 - result); Assert.IsTrue(error <= epsilon * 10); }
private void button2_Click(object sender, EventArgs e) { string maxIt = Interaction.InputBox("Max iteration : ", "Max iteration", "Exp : 50", 0, 0); int maxIteration = Convert.ToInt32(maxIt); string eps = Interaction.InputBox("Epsilon : ", "Epsilon", "Exp : 0.000001", 0, 0); double Epsilon = Convert.ToDouble(eps); var solver = new NewtonRaphson(); if (radioButton1.Checked) { double root = solver.Solve(x => x * x - 2, x => 2 * x, 1, maxIteration, Epsilon); listBox2.Items.Add(root); } else if (radioButton2.Checked) { double root2 = solver.Solve(x => x - Math.Cos(x), x => 1 + Math.Sin(x), 2, maxIteration, Epsilon); listBox2.Items.Add(root2); } else { MessageBox.Show("Choose a equation"); } }