Challenge: Linear System Solver

Design a Python algorithm to solve a system of linear equations.

Statement

Given a system of two linear equations with two unknowns, w1w_1 and w2w_2, determine if there’s a potential solution. In the case of multiple solutions, return the string “There are infinitely many solutions” in the output. In the case of no solution, return the string “Intersection does not exist” in the output.

Example

Consider an example linear system:

2w14w2=92w_1-4w_2=9

3w1+7w2=33w_1+7w_2=3

The solution to the system is (w1,w2)=(25.5,10.5)(w_1,w_2) = (25.5,-10.5)

Sample inputs and outputs

The following table describes the desired outputs, given the corresponding inputs to the system above, and a few other examples.

Input Output
e1:[2,4,9]e1 : [2, 4, 9] , e2:[3,7,3]e2 : [3, 7, 3] 25.500 , -10.500
e1:[2,2,4]e1 : [2, 2, 4] , e2:[4,4,8]e2 : [4, 4, 8] There are infinitely many solutions
e1:[2,4,9]e1 : [2, 4, 9] , e2:[2,4,3]e2 : [2, 4, 3] Intersection does not exist

Note: The output is a string in all cases.

Try it yourself

The signature of the function is given below. It accepts two arrays containing the scalars of the system of linear equations.

Get hands-on with 1200+ tech skills courses.