Question: 5. Implement quadratic.py You will be writing functions to characterize the solutions of quadratic equations in the standard form ax^2 + bx + c =

5. Implement quadratic.py

You will be writing functions to characterize the solutions of quadratic equations in the standard form

ax^2 + bx + c = 0

and find real solutions, if they exist.

5a. Determining the Discriminant (3 points)

The discriminant of a quadratic equation is the quantity

d = b^2 - 4ac

The discriminant determines the nature of roots of a quadratic equation.

Your task is to implement a function with the following signature:

def discriminant(a:float, b:float, c:float) -> float 

The function takes as arguments three floats a, b, c, as described above and returns the discriminant of the quadratic equation described by the specified parameters.

Example:

discriminant(6, 10, -1) # This should return 124 discriminant(1, -3, 4) # This should return -7 

5b. Check for the existence of real roots (3 points)

A well known result in mathematics states that a quadratic equation has real roots if and only if the discriminant is strictly greater than 0.

Your task is to implement a function with the following signature:

def has_real_root(a:float, b:float, c:float) -> bool 

The function takes as arguments three floats a, b, c, as described above and returns the if the quadratic equation described by the specified parameters has real roots or not.

Example:

has_real_root(6, 10, -1) # This should return True has_real_root(1, -3, 4) # This should return False 

Hint: Reuse 5a. to calculate the discriminant.

5c. Calculate a real root (3 points)

Using the discriminant, we can write the roots of the quadratic equation as

x1 = (-b + sqrtrt(d)) / (2a) and x2 = (-b - sqrtrt(d)) / (2a)

Your final task is to implement a function with the following signature:

def get_any_real_root(a:float, b:float, c:float) -> float 

The function takes as arguments three floats a, b, c, as described above and returns any one root of the the quadratic equation described by the specified parameters. It should return a root only if the equation specified by the parameters has real roots otherwise should give an error.

Hint: For the error, use an assert statement with one of the functions 5a. - 5b.

Example:

get_any_real_root(1, -7, 10) # This should return 2 or 5 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!