roots of a quadratic equation
Quadratic equations can be represented by three numbers, a
, b
, and c
, which are the coefficient of x^2
, the coefficient of x
, and the constant term. The roots of a quadratic equation are everywhere where it touches the x axis, meaning the equation is equal to zero.
You can use the quadratic formula which calculates the roots. In fact, that's your task: write a function that returns the roots of a quadratic equation using the quadratic formula. Here is more information about it.
Note: you don't have to return complex roots if the curve does not cross the x-axis.
Thanks to this site for the challenge idea where it is considered Medium level in Python.
Email submissions to eric@purelyfunctional.tv before July 12, 2020. You can discuss the submissions in the comments below.
Is anyone also interested in implementing the full functionality, i.e. for negative discriminants as well? The reference notes show that the complex roots can also be neatly expressed using real coordinates.
I suggest something like below to make and detect complex numbers - the idea is to be able to test all implementations uniformly. So for example a test could simply use the functions below to detect and extract values in order to verify results.
So a solution could simply reference this externally (to reduce clutter), and use it to make complex numbers accordingly. So for example, a result value could be any one of [m], [m, n] or [(complex a b), (complex c d)] where m, n are regular numbers - and so forth.
Any comment? Thanks.