Skip to content

num::newton

Defined in header <roots/roots.hpp>

template <typename Float = double, std::invocable<Float> Func = scalar_fn,
          std::invocable<Float> DFunc = scalar_fn>
root_result<Float> newton(Func &&f, DFunc &&df, Float x0, Float tol = Float{1e-10},
                          idx max_iter = 1000);

Newton–Raphson method with quadratic convergence using analytical derivative \(f'(x)\).

Iteratively computes \(x_{k+1} = x_k - \frac{f(x_k)}{f'(x_k)}\). Achieves quadratic convergence \(\mathcal{O}(\epsilon^2)\) near simple roots.

Template parameters

  • Float: Floating point type.
  • Func: Target function callable Float(Float x).
  • DFunc: Derivative function callable Float(Float x).

Parameters

  • f: Target function \(f(x)\).
  • df: Derivative function \(f'(x)\).
  • x0: Initial root estimate.
  • tol: Residual convergence tolerance \(|f(x)| < \text{tol}\) (default: 1e-10).
  • max_iter: Maximum iterations (default: 1000).

Return value

root_result<Float> with root estimate and convergence info.

See also

secant, brent, bisection