problemAIAlgebra 2
Two lines cross
Two straight lines, and , meet at one point unless they are parallel. Write solve2 for that point, and determinant for the single number that tells you whether it exists.
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.
Elimination, substitution, Cramer's rule: they are the same arithmetic in three arrangements, and any of them solves this. The lines and cross at , and so do and : a different pair of lines through the same point. A third pair crosses at , so an answer that always returns fails.
The last test checks a failure. Slide one line until it is parallel
to the other and the crossing runs off to infinity; something in the arithmetic must
have gone to zero at that moment. Find what, and that is determinant.
Your task
Write these 2 functions:
solve2(a, b, c, d, e, f)- The point (x, y) where ax + by = c and dx + ey = f cross. Assume they do.
determinant(a, b, d, e)- \det = ae - bd: zero exactly when the two lines are parallel.
Make these tests pass 4 of 4 fail
- x + y = 5 and x - y = 1 cross at (3, 2) assert_near: |0 - 3| = 3 > 1e-12 (and 1 more) (fails)
- 2x + 3y = 12 and x - y = 1 cross at (3, 2) too assert_near: |0 - 3| = 3 > 1e-12 (and 1 more) (fails)
- 3x - 2y = 4 and 5x + 4y = 14 cross at (2, 1), and the point satisfies both assert_near: |0 - 4| = 4 > 1e-12 (and 1 more) (fails)
- the determinant is zero for parallel lines and -2 for x + y, x - y assert_near: |0 - -2| = 2 > 1e-12 (fails)
Printed