Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/FabianeloV/Metodo-simplex/llms.txt

Use this file to discover all available pages before exploring further.

The Newton-Raphson method finds a stationary point of a single-variable polynomial by iteratively improving an initial estimate x₀ using the recurrence: xn+1=xnf(xn)f(xn)x_{n+1} = x_n - \frac{f'(x_n)}{f''(x_n)} Each step moves in the direction that reduces |f′(x)| most sharply, using f″(x) as the local curvature to scale the correction. Convergence is quadratic near a true stationary point — the number of correct decimal places roughly doubles with each iteration — making it substantially faster than bisection for well-behaved smooth functions. In exchange it requires a starting point x₀ rather than a bracketing interval, and it can fail to converge if x₀ is far from the solution, if f″ is near zero, or if the function has inflection points in the neighbourhood.

Comparison with Bisection

PropertyBisectionNewton-Raphson
Inputs requiredInterval [a, b] with sign change of f′Starting point x₀
Convergence rateLinear (halves interval each step)Quadratic near solution
Requires f″NoYes
Guaranteed to converge?Yes, when bracketing holdsNo — may diverge
Risk of divergenceNone (within bracket)Near inflection points or poor x₀

Endpoint

POST /newton/solve

Request

coefficients
float[]
required
Polynomial coefficients listed from highest to lowest degree (NumPy convention). Must contain between 1 and 11 elements; the list must not be identically zero.Example: [-1, 0, 4, 0] encodes f(x) = −x³ + 4x.
coefficientsf(x)
[-1, 4, 0]−x² + 4x
[1, -6, 9, 0]x³ − 6x² + 9x
[1, 0, -5, 0]x³ − 5x
goal
string
required
Optimization direction: "max" or "min". The engine uses f″(x*) to classify the converged point and sets goal_satisfied accordingly.
x0
float
required
Initial guess for the iterative procedure. The choice of x₀ significantly affects which stationary point (if any) the method converges to. For multimodal functions, try different starting values to locate distinct optima.
tolerance
float
default:"1e-6"
Convergence criterion. Iteration stops when |f′(xₙ)| < tolerance or |xₙ₊₁ − xₙ| < tolerance. Must be in the range (0, 1].
max_iterations
integer
default:"100"
Maximum number of Newton-Raphson steps. Must be between 1 and 500. If the method has not converged after this many steps, status is set to "no_convergence".

Response

status
string
Final status of the solver:
  • "optimal" — a stationary point was found within the tolerance and iteration limits.
  • "no_convergence" — the method did not converge within max_iterations steps. The last iterate is still returned in optimal_x for inspection.
optimal_x
float | null
The x-coordinate of the stationary point found (or the last iterate when status = "no_convergence").
optimal_value
float | null
The function value f(optimal_x).
nature
string | null
Classification of the stationary point using the second-derivative test on f″(x*):
  • "mínimo" — local minimum (f″ > 0).
  • "máximo" — local maximum (f″ < 0).
  • "punto de inflexión" — saddle or inflection point (f″ ≈ 0).
goal_satisfied
boolean
true when nature matches the requested goal (e.g. goal = "min" and nature = "mínimo").
iterations_count
integer
Number of Newton-Raphson steps actually performed.
iterations
NewtonIteration[]
Complete per-step trace of the iteration sequence.
function_str
string
Human-readable representation of f(x), e.g. "-x² + 4x".
derivative_str
string
Human-readable representation of f′(x), e.g. "-2x + 4".
second_derivative_str
string
Human-readable representation of f″(x), e.g. "-2". This field is unique to the Newton-Raphson response and is not present in the Bisection response.
message
string
Narrative summary of the result. Includes the converged point, its nature, whether the goal was matched, and actionable guidance when the method did not converge or found the wrong type of stationary point.

Example

Find the maximum of f(x) = −x² + 4x starting from x₀ = 1:
curl -X POST http://localhost:8000/newton/solve \
  -H "Content-Type: application/json" \
  -d '{
    "coefficients": [-1, 4, 0],
    "goal": "max",
    "x0": 1.0,
    "tolerance": 1e-6,
    "max_iterations": 100
  }'
{
  "status": "optimal",
  "optimal_x": 2.0,
  "optimal_value": 4.0,
  "nature": "máximo",
  "goal_satisfied": true,
  "iterations_count": 2,
  "iterations": [
    {
      "iteration": 1,
      "x_n": 1.0,
      "f_xn": 3.0,
      "df_xn": 2.0,
      "d2f_xn": -2.0,
      "x_next": 2.0,
      "step": 1.0
    },
    {
      "iteration": 2,
      "x_n": 2.0,
      "f_xn": 4.0,
      "df_xn": 0.0,
      "d2f_xn": -2.0,
      "x_next": 2.0,
      "step": 0.0
    }
  ],
  "function_str": "-x² + 4x",
  "derivative_str": "-2x + 4",
  "second_derivative_str": "-2",
  "message": "Óptimo encontrado: x = 2 es un máximo de la función, coincidiendo con la meta solicitada (máximo)."
}
For a pure quadratic like −x² + 4x, the Newton step from x₀ = 1 lands exactly on x = 2 after the first correction. However, convergence is only declared once the engine re-evaluates f′ at the new point and confirms |f′(xₙ)| < tolerance — so two iterations are recorded: the first produces x_next = 2.0, and the second confirms f′(2.0) = 0. For higher-degree polynomials, additional iterations are generally required.

Convergence Pitfalls

Divergence near inflection points. If f″(xₙ) ≈ 0 during iteration, the Newton step becomes extremely large and the sequence diverges. The engine detects |f″| < 1 × 10⁻¹⁴ and immediately returns a 422 error with a suggestion to try a different x₀.
no_convergence status. When the method exhausts max_iterations without satisfying the tolerance, status is set to "no_convergence" rather than "optimal". The optimal_x field still contains the last computed iterate, which may be useful for diagnosing the starting point. Increase max_iterations or choose an x₀ closer to the expected solution.
Saddle / inflection points. When f″(x*) ≈ 0 at the converged point, nature is "punto de inflexión" and goal_satisfied will be false. The method has found a stationary point, but the second-derivative test is inconclusive — neither a minimum nor a maximum is confirmed.
Wrong type of stationary point. Newton-Raphson converges to the nearest stationary point of f′, which might be a minimum when you requested a maximum. In this case status is still "optimal" but goal_satisfied is false. Try a starting point x₀ on the other side of the function’s inflection point to target the desired extremum type.

Build docs developers (and LLMs) love