New exercise suggestion: Cubic Solver

In January, there was a suggestion Extend Square Root to Work With Floating Points?. Many of the goals from that proposal can be achieved by introducing a new exercise.

The polynomial equation 144060 x^3 - 47988 x^2 - 3211091 x + 1703680 = 0 has solutions x ≈ -4.81098, x ≈ 0.533111, x ≈ 4.61098

Students will be asked to implement a method such that

solve( [144060, -47988, -3211091, 1703680] ) will return the solutions [-4.81098, 0.533111, 4.61098], in any order.

Each test case polynomial will have integer coefficients, and be chosen to have 3 distinct real roots, including at least one rational root.

This allows a variety of solution methods, such as

  • Newton’s method
  • Cardano’s formula
  • Guessing a rational root, then using the quadratic formula
  • Binary chop

I don’t have a specific story suggestion. Here are some applications of cubics.

IMHO, this might be a bit too mathy. We’ve found that the more mathy exercises tend to be less popular with people and many struggle with them. That’s not to say we shouldn’t implement any math exercises, but it would not be my preference to do so.