how to find the roots of any given polynomial using newton raphson method
if any one have the code plz share it

Dani AI

Generated

A compact, practical roadmap for implementing Newton–Raphson on a 5th‑degree polynomial (and why a library is often the safer choice).

Newton’s update is x_{k+1} = x_k - f(x_k)/f'(x_k). For polynomials the derivative is cheap to get from the coefficients, and Horner’s method evaluates f and f' with minimal operations. Newton finds one root at a time; to get all roots either deflate the polynomial after each converged root (synthetic division) or use a global method that finds all roots simultaneously (Durand–Kerner, companion-matrix / eigenvalue methods). Common failure modes: poor initial guesses, multiple/repeated roots (convergence drops to linear), near-zero derivative (division blow-up), and roundoff accumulation during repeated deflation.

Implementation notes and numeric safeguards:

  • Store coefficients in descending order and use complex arithmetic (std::complex<double>) so complex roots are handled naturally.
  • Evaluate f and f' together via Horner. Stop when |dx| < tol*max(1,|x|) or |f(x)| < tol; cap iterations.
  • If |f'| is extremely small, apply a tiny complex perturbation or switch strategy (damped Newton, or a fallback global method).
  • After finding a root r, perform synthetic division to produce the reduced polynomial and repeat. Because deflation can drift earlier roots, periodically “polish” found roots by re-running Newton on the original polynomial.
  • For production or tight-robustness needs prefer a tested library (as noted); for learning, the steps above illuminate the issues mentioned about trying and debugging.

Example C++ sketch (descending coeffs, complex-aware):

#include <vector>
#include <complex>

using cd = std::complex<double>;
using vd = std::vector<cd>;

cd evalPolyAndDeriv(const vd &a, const cd &x, cd &deriv) {
    int n = (int)a.size()-1;
    cd b = a[0], d = cd(0);
    for (int i=1;i<=n;++i){ d = d*x + b; b = b*x + a[i]; }
    deriv = d; return b;
}

// newtonRoot, deflate shown in same style as above

For clarity: asked about degree 5 specifically — the above applies directly, with the caveat that seeking all five roots reliably usually means combining Newton + deflation carefully or using a robust polynomial-root routine.

Recommended Answers

All 3 Replies

assume an equation from the 5th degree ?!

wth is the newton raphson method? did you try at all? take it all step by step and try to develop something rather than just asking others to do everything for you... if your stuck with a error or genuine programming problem (after TRYING) we will be happy to help

If you just want to solve polynomials, then you could use an existing library (for example GSL has polynomial solving). Of course, if this is some kind of assignment, then that probably won't help very much. In which case, you should post an example of what you have attempted so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.