How can I design an algorithm for calculating n roots of a polynomial? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I design an algorithm for calculating n roots of a polynomial?

I wish to make a C++ program to calculate n roots of a polynomial of n degree, and print them, even if they are real or complex... I know that one can easily use quadratic formula for a quadratic equation, but are there formulas for other roots? Is there a generalized way for an n degree polynomial using calculus or some other branch? Or do there exist other formulas for this purpose (like for cubic, quartic, etc)? Please help me, as I haven't encountered these topics in mathematics yet... Thank You!

11th Jun 2017, 4:03 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
5 Answers
+ 5
Good question...the link advises to "linearise the problem". If an initial value is too far off, the method might not converge. You might want to look into the Stochastic Funnel Algorithm to optimize the method.
11th Jun 2017, 4:27 PM
Karl T.
Karl T. - avatar
+ 4
You could use Newton's numerical method. https://en.m.wikipedia.org/wiki/Newton%27s_method
11th Jun 2017, 4:15 PM
Karl T.
Karl T. - avatar
+ 2
@Karl T. Thank You, Sir! But I have a doubt... How will I approximate the first root for the polynomial equation? //As, it can even be complex...
11th Jun 2017, 4:21 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
@Karl T. Ill check more into that. Thank You Sir!
11th Jun 2017, 4:28 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Please do note that I can calculate some derivatives and integrals of expressions and complex functions using the symbolic c++ library I found a few days ago...
11th Jun 2017, 4:04 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar