root-finding
npx machina-cli add skill parcadei/Continuous-Claude-v3/root-finding --openclawRoot Finding
When to Use
Use this skill when working on root-finding problems in numerical methods.
Decision Tree
-
Characterize the Problem
- Single root or multiple roots?
- Bracketed (know interval containing root)?
- Derivatives available?
-
Method Selection
Situation Method Implementation Bracketed, no derivatives Bisection, Brent scipy.optimize.brentqDerivatives available Newton-Raphson scipy.optimize.newtonNo derivatives Secant method scipy.optimize.newton(no fprime)System of equations scipy.optimize.fsolveRequires Jacobian ideally -
Implement Root Finding
scipy.optimize.brentq(f, a, b)- guaranteed convergence if bracketedscipy.optimize.newton(f, x0, fprime=df)- quadratic convergence near root- For systems:
scipy.optimize.fsolve(F, x0)
-
Handle Multiple Roots
- Deflation: divide out found roots
- Multiple starting points
sympy_compute.py solve "f(x)" --var xfor symbolic solutions
-
Verify Solutions
- Check |f(root)| < tolerance
- Verify root is in expected domain
z3_solve.py prove "f(root) == 0"
Tool Commands
Scipy_Brentq
uv run python -c "from scipy.optimize import brentq; root = brentq(lambda x: x**2 - 2, 0, 2); print('Root:', root)"
Scipy_Newton
uv run python -c "from scipy.optimize import newton; root = newton(lambda x: x**2 - 2, 1.0, fprime=lambda x: 2*x); print('Root:', root)"
Sympy_Solve
uv run python -m runtime.harness scripts/sympy_compute.py solve "x**3 - x - 1" --var x
Key Techniques
From indexed textbooks:
- [Numerical analysis (Burden R.L., Fair... (Z-Library)] How accurate was his approximation? C H A P T E R 2 Solutions of Equations in One Variable 2. Survey of Methods and Software In this chapter we have considered the problem of solving the equation f (x) = 0, where f is a given continuous function.
- [An Introduction to Numerical Analysis... (Z-Library)] Computational Solution of Nonlinear Operator Equations. Methods for Solving Systems of Nonlinear Equations. Society for Industrial and Applied Mathematics, Philadelphia.
- [An Introduction to Numerical Analysis... (Z-Library)] General polynomial rootfinding methods There are a large number of rootfind ing algorithms designed especially for polynomials. Many of these are taken up in detail in the books Dejon and Henrici (1969), Henrici (1974, chap. There are far too many types of such methods to attempt to describe them all here.
- [An Introduction to Numerical Analysis... (Z-Library)] J n Consider the product a 0 a 1 ••• am, where a 0 , a1, ••• , am are m + 1 num bers stored in a computer that uses n digit base fJ arithmetic. What is a rigorous bound for w? What is a statistical estimate for the size of w?
- [An Introduction to Numerical Analysis... (Z-Library)] Discussion of the Literature There is a large literature on methods for calculating the roots of a single equation. See the books by Householder (1970), Ostrowski (1973), and Traub (1964) for a more extensive development than has been given here. Newton's method is one of the most widely used methods, and its development is due to many people.
Cognitive Tools Reference
See .claude/skills/math-mode/SKILL.md for full tool documentation.
Source
git clone https://github.com/parcadei/Continuous-Claude-v3/blob/main/.claude/skills/math/numerical-methods/root-finding/SKILL.mdView on GitHub Overview
This skill guides solving equations f(x)=0 using numerical methods. It covers choosing methods based on bracketedness and derivatives, implementing with SciPy, and verifying roots. It also addresses handling multiple roots and systems of equations.
How This Skill Works
Assess the problem: single vs multiple roots, bracket availability, and whether derivatives exist. Choose a method accordingly (brentq for bracketed problems, Newton for available derivatives, or secant when no derivative is available; fsolve for systems). Implement using the provided function calls and then verify results for correctness.
When to Use It
- Bracketed root with no derivatives (use brentq or Brent in SciPy)
- Derivatives available (use Newton-Raphson for fast convergence)
- No derivatives but need a root (use secant via newton without fprime)
- System of equations (use fsolve with a Jacobian ideally)
- Need to handle multiple roots and verify feasibility
Quick Start
- Step 1: Identify if the problem is bracketed and whether derivatives are available
- Step 2: Choose the method (brentq for bracketed; newton for derivatives; fsolve for systems) and call the appropriate SciPy function
- Step 3: Verify the root with |f(root)| < tol and apply deflation or multiple starts if needed
Best Practices
- Characterize the problem: determine if roots are single or multiple and whether a bracket is known
- Choose method based on derivatives and bracket information (brentq for bracketed, newton for derivatives, fsolve for systems)
- Implement robustly with the recommended SciPy calls (brentq, newton, fsolve)
- Handle multiple roots via deflation or multiple starting points, or symbolic solving when possible
- Verify solutions by ensuring |f(root)| is within tolerance and the root lies in the expected domain
Example Use Cases
- Find sqrt(2) using brentq(f, 0, 2) to demonstrate bracketed root finding
- Use Newton-Raphson with f(x)=x^2-2 and f'(x)=2x starting at x0=1.0
- Symbolically solve x^3 - x - 1 with Sympy as a cross-check
- Solve a small system with fsolve for F(x) = [g1(x,y), g2(x,y)] starting from a guess
- Deflate after finding a root to locate remaining roots of a polynomial equation