problemAIAlgebra 2
Solve the quadratic
A ball is thrown straight up at 4 m/s from 1 m above the ground. When does it land? Write roots(a, b, c), the two solutions of , smaller first.
Open in the workbenchDownload .vivOutputs below are from the site build’s run; Run all runs it again in your browser.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
A ball is thrown straight up at 4 m/s from 1 m above the ground. With rounded to 10 m/s², its height after seconds is
It lands when , that is, when .
Write roots(a, b, c), the two solutions of , smaller first. You may assume . The tests use the ball and a rectangle with a perimeter of 10 and an area of 6, whose sides and satisfy .
Your task
Write this function:
roots(a, b, c)- The two roots of the quadratic with coefficients a, b and c, smaller first.
Make these tests pass 2 of 2 fail
- $x^2 - 5x + 6 = 0$ gives 2 and 3 assert_near: |0 - 2| = 2 > 1e-12 (and 1 more) (fails)
- $-5t^2 + 4t + 1 = 0$ gives -0.2 and 1, smaller first assert_near: |0 - -0.2| = 0.2 > 1e-12 (and 1 more) (fails)
Printed