Skip to content
DeepForgeby svx
All problems
EasyCalculusca-059

Characteristic Equation Roots

Problem

Find the roots of the characteristic equation lambda^2 + b*lambda + c = 0.

Return both real roots sorted in ascending order. If the discriminant b^2 - 4*c is negative, return an empty list. A repeated root is returned twice.

Hint

Use the quadratic formula; the discriminant decides how many real roots exist.

Test cases

case 1
in: [-5,6]
expected: [2,3]
case 2
in: [0,1]
expected: []
case 3
in: [2,1]
expected: [-1,-1]
case 4
in: [-4,4]
expected: [2,2]
case 5
in: [3,2]
expected: [-2,-1]
Starter codePython
def char_roots(b, c):
    # Your code here
    pass

5 test cases · run your code against them in the editor