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 8823073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:15:50+00:00 2026-06-14T06:15:50+00:00

I have a program I’m writing in which the user has the option to

  • 0

I have a program I’m writing in which the user has the option to choose between solving a cubic function for either second or third degree polynomials. Once choosing, the program applies a number of formulas, including: solving the 2nd degree discriminant, the quadratic formula, the formula for polynomials of the second degree, Cardano’s analogous method of third degree polynomials, and the standard cubic formula (basically, the first four formulas on this page).

Here’s my code:

import math

def deg3():
    print("This is a third degree polynomial calculator.")
    print("Please enter four numbers.")
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())

# Apply Cardano's compressed method to find x root, broken up into different variables.
p = (-1 * b)/(3 * a)
q = p ** 3 + (b * c - (3 * a * d))/ (6 * (a ** 2)) 
r = c / (3 * a)

x = (q + (q**2 + (r - p**2)**3) **1/2) **1/3 + (q + (q**2 + (r - p**2)**3) **1/2) **1/3 + p
print("The root is:", x)

# Applies final cubic formula, and returns.
total = (a * x**3) + (b * x**2) + (c * x) + d
total = round(total, 3)
return total

# If discr > 0, then the equation has three distinct real roots.
# If discr = 0, then the equation has a multiple root and all its roots are real.
# If discr < 0, then the equation has one real root and
# two nonreal complex conjugate roots.

Now it easily returns a total. The computation is correct, but I’m still trying to wrap my brain around the analogous formula. What is the discriminant part of the equation? How do I find potential roots, like I do with the quadratic formula? Probably a no-brainer question, but I want to understand the process better.

  • 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-06-14T06:15:52+00:00Added an answer on June 14, 2026 at 6:15 am

    First, there are many differences between your cubic function and the equation on the site you link to. Among the most notable:

    1. Your order of operations is off: a line like:

      big = (-1 *( b**3 / 27 * a**3) + (b * c / 6 * a**2) - (d / 2 * a))
      

      should be:

      big = (-1 *( b**3 / (27 * a**3)) + (b * c / (6 * a**2)) - (d / (2 * a)))
      

      otherwise, a term like 27 * a**3 won’t end up in the denominator- it will instead be seen as 27 in the denominator and a**3 afterwards.

    2. You never include a cube root, even though there are two in the equation you link to.

    3. You do x * 2 - small, but the two items added together in the equation are not identical- one has a plus sign where the other has a minus.

    However, even if you fix all the issues with the function, you will still get a math domain error when trying to solve many cubic equations. Note this paragraph from your link:

    But if we apply Cardano’s formula to this example, we use a=1, b=0, c=-15, d=-4, and we find that we need to take the square root of -109 in the resulting computation. Ultimately, the square roots of negative numbers would cancel out later in the computation, but that computation can’t be understood by a calculus student without additional discussion of complex numbers.

    Solving cubic equations requires dealing with complex numbers (though only temporarily- as noted, they’ll cancel out), so you can’t use math.sqrt to solve it. You might be interested in the cmath package.

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

Sidebar

Related Questions

I have program.cpp which contains main function. There is a class Tracker which is
I'm confused. I have program which I run as a non-administrator user. This program
I have program which has servers interacting with each other using Twisted's remote procedure
I have program that has a variable that should never change. However, somehow, it
I have a program which creates JButtons which are then added to a JPanel
I have a program with a MenuStrip at the top, it currently has 4
I have program which writes to database which folders are full or empty. Now
i have program which prints all char from char_min to char_max here is code
Here is my situation: I have program A which looks like this: Fmfile IF
Have a program request the user to enter an uppercase letter. Use nested loops

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.