Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3871838
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:51:44+00:00 2026-05-19T21:51:44+00:00

this seems like an obvious question to me, but I couldn’t find it anywhere

  • 0

this seems like an obvious question to me, but I couldn’t find it anywhere on SO.
I have a cubic polynomial and I need to find real roots of the function. What is THE way of doing this?

I have found several closed form formulas for roots of a cubic function, but all of them use either complex numbers or lots of goniometric functions and I don’t like them (and also don’t know which one to choose).

I need something simple; faster is better; and I know that I will eventually need to solve polynomials of higher order, so having a numerical solver would maybe help too.
I know I could use some library to do the hard work for me, but lets say I want to do this as an exercise.

I’m coding in C, so no import magic_poly_solver, please.

Bonus question: How do I find only roots inside a given interval?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:51:45+00:00Added an answer on May 19, 2026 at 9:51 pm

    For a cubic polynomial there are closed form solutions, but they are not particularly well suited for numerical calculus.

    I’d do the following for the cubic case: any cubic polynomial has at least one real root, you can find it easily with Newton’s method. Then, you use deflation to get the remaining quadratic polynomial to solve, see my answer there for how to do this latter step correctly.

    One word of caution: if the discriminant is close to zero, there will be a numerically multiple real root, and Newton’s method will miserably fail. Moreover, since to the vicinity of the root, the polynomial is like (x – x0)^2, you’ll lose half your significant digits (since P(x) will be < epsilon as soon as x – x0 < sqrt(epsilon)). So you may want to rule this out and use the closed form solution in this particular case, or solve the derivative polynomial.

    If you want to find roots in a given interval, check Sturm’s theorem.

    A more general (complex) algorithm for generic polynomial solving is Jenkins-Traub algorithm. This is clearly overkill here, but it works well on cubics. Usually, you use a third-party implementation.

    Since you do C, using the GSL is surely your best bet.

    Another generic method is to find the eigenvalues of the companion matrix with eg. balanced QR decomposition, or reduction to Householder form. This is the approach taken by GSL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a fairly obvious question, but I haven't been able to think
This might sound like an obvious question but I can't seem to find the
This seems like the simplest Git question, but I can't find ANYTHING on it.
This seems like I'm missing something obvious but I can't get redirects (>) to
This seems like it should be obvious but I can't figure it out. Suppose
Seems like this should be obvious, but how do I send arrow key presses
This seems like a repeated question but i'm not able to get my answer.
This seems like such a simple issue but I cannot find an elegant solution.
Be forewarned: This question seems way more obvious than it actually is. I'd like
I can only imagine I'm not searching correctly; this seems like an obvious question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.