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.
Cool, and I love the use of Klipse! It would be great to see more explanatory text though! What does quadratic-rational do, and how does "factor and remove perfect squares" help get you there. And what's the connection between those those and your quadratic-roots code? I'm also enjoying your other posts, e..g. the sudoku solver and minesweeper in reagent are really neat.
Btw, related to this challenge, I wrote a function to to extract coefficients from a symbolic representation of a quadratic:
(->coeffs "45x^2-42x+3") => [45 -42 3] ..but it was surprisingly hard, and I'm not thrilled with it. Seems like this is something you might have already solved in a more elegant way..