All problems
Critical Points of a Cubic
Problem
Find all real critical points of the cubic f(x) = a*x^3 + b*x^2 + c*x + d by solving f'(x) = 3*a*x^2 + 2*b*x + c = 0.
Return the distinct real roots sorted in ascending order (an empty list if there are none). The constant d does not affect the result.
Hint
Solve the quadratic f'(x) = 0 with the discriminant and keep only real roots.
Test cases
case 1
in: [1,0,-3,0]
expected: [-1,1]
case 2
in: [1,-3,2,0]
expected: [0.42264973081037427,1.5773502691896257]
case 3
in: [0,1,-4,5]
expected: [2]
case 4
in: [1,0,1,0]
expected: []
case 5
in: [1,0,0,0]
expected: [0]
Starter codePython
def critical_points(a, b, c, d):
# Return a sorted list of critical x values
# Your code here
pass5 test cases · run your code against them in the editor