public GetParameterHelper1F() { _rootFinder = new ImprovedNewtonRaphsonMethodF(GetPoint, GetTangent); }
public GetParameterHelper3F() { _rootFinder = new ImprovedNewtonRaphsonMethodF(GetLength, GetTangentLength); }
// This method shows how to use root finding. // A method y = Foo(x) is given and we want to find x such that Foo(x) = 7. private void FindRoot() { var debugRenderer = GraphicsScreen.DebugRenderer2D; debugRenderer.DrawText("----- RootFinding Example:"); // Create a new instance of a root finder class. // The Newton-Raphson root finding method uses the function and the first-order // derivative of the function where we want to find solutions. If the derivate // is not known, other root finding classes can be used, like the BisectionMethod // or RegulaFalsiMethod classes. var rootFinder = new ImprovedNewtonRaphsonMethodF(Foo, FooDerived); // Several x could result in Foo(x) = 7. So we need to define an x interval // that contains the desired x solution. // We decide to look for a solution near x = 0 and let the rootFinder approximate // an x interval that contains the result. float x0 = 0; float x1 = 0; // Find an interval [x0, x1] that contains an x such that Foo(x) = 7. rootFinder.ExpandBracket(ref x0, ref x1, 7); // Now we use the root finder to find an x within [x0, x1] such that Foo(x) = 7. float x = rootFinder.FindRoot(x0, x1, 7); // Lets check the result. float y = Foo(x); // Important note: We use Numeric.AreEqual() to safely compare floating-point numbers. if (Numeric.AreEqual(y, 7)) debugRenderer.DrawText("Solution is correct.\n"); else debugRenderer.DrawText("Solution is wrong.\n"); }