public static void Test() { GSLFunctions.DToD dtodFnc = delegate(double x) { Console.WriteLine(x); return x * x - 5; }; Root root; double xValue; root = new Root(Root.SolverType.FalsePosition); root.ConvergenceType = Root.Convergence.Delta; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---"); root.ConvergenceType = Root.Convergence.Interval; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---"); root.ConvergenceType = Root.Convergence.Residual; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---***---"); root = new Root(Root.SolverType.BrentDekker); root.ConvergenceType = Root.Convergence.Delta; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---"); root.ConvergenceType = Root.Convergence.Interval; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---"); root.ConvergenceType = Root.Convergence.Residual; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---***---"); root = new Root(Root.SolverType.FalsePosition); root.ConvergenceType = Root.Convergence.Delta; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---"); root.ConvergenceType = Root.Convergence.Interval; root.Solve(dtodFnc, 0, 5, 100, out xValue); Console.WriteLine("---"); root.ConvergenceType = Root.Convergence.Residual; root.Solve(dtodFnc, 0, 5, 100, out xValue); }
public static void Test() { GSLFunctions.DToD dtodFnc = delegate(double x) { return(Math.Cos(x) + 1.0d); }; Minimization mini = new Minimization(Minimization.SolverType.Brent); double xValue = 2; mini.Solve(dtodFnc, 0, 6, 0.001, 0, 100, ref xValue); Console.WriteLine(xValue + " : " + mini.Iteration()); mini = new Minimization(Minimization.SolverType.GoldenSection); xValue = 2; mini.Solve(dtodFnc, 0, 6, 0.001, 0, 100, ref xValue); Console.WriteLine(xValue + " : " + mini.Iteration()); }
public static void Test() { GSLFunctions.DToD dtodFnc = delegate(double x) { return(x * x - 5); }; GSLFunctions.DToD dtodFncDF = delegate(double x) { return(2 * x); }; RootWithDerivative root; double xValue; xValue = 2; root = new RootWithDerivative(RootWithDerivative.SolverType.Newton); root.ConvergenceType = RootWithDerivative.Convergence.Delta; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---"); xValue = 2; root.ConvergenceType = RootWithDerivative.Convergence.Residual; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---***---"); xValue = 2; root = new RootWithDerivative(RootWithDerivative.SolverType.Secant); root.ConvergenceType = RootWithDerivative.Convergence.Delta; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---"); xValue = 2; root.ConvergenceType = RootWithDerivative.Convergence.Residual; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---***---"); xValue = 2; root = new RootWithDerivative(RootWithDerivative.SolverType.Steffenson); root.ConvergenceType = RootWithDerivative.Convergence.Delta; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---"); xValue = 2; root.ConvergenceType = RootWithDerivative.Convergence.Residual; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---***---***---"); xValue = 2; root = new RootWithDerivative(RootWithDerivative.SolverType.Newton); root.ConvergenceType = RootWithDerivative.Convergence.Delta; root.Solve(dtodFnc, dtodFncDF, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---"); xValue = 2; root.ConvergenceType = RootWithDerivative.Convergence.Residual; root.Solve(dtodFnc, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---***---"); xValue = 2; root = new RootWithDerivative(RootWithDerivative.SolverType.Secant); root.ConvergenceType = RootWithDerivative.Convergence.Delta; root.Solve(dtodFnc, dtodFncDF, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---"); xValue = 2; root.ConvergenceType = RootWithDerivative.Convergence.Residual; root.Solve(dtodFnc, dtodFncDF, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---***---"); xValue = 2; root = new RootWithDerivative(RootWithDerivative.SolverType.Steffenson); root.ConvergenceType = RootWithDerivative.Convergence.Delta; root.Solve(dtodFnc, dtodFncDF, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); Console.WriteLine("---"); xValue = 2; root.ConvergenceType = RootWithDerivative.Convergence.Residual; root.Solve(dtodFnc, dtodFncDF, 100, ref xValue); Console.WriteLine(root.Iteration() + " : " + xValue); }