From dffc7898759be59e65f9f08e876748985f3b23ab Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 02:42:40 +0530 Subject: [PATCH 1/7] Create linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 maths/linear_equations_in_two_variables.py diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py new file mode 100644 index 000000000000..82cf3a96afd8 --- /dev/null +++ b/maths/linear_equations_in_two_variables.py @@ -0,0 +1,20 @@ +''' +Solves linear equations in two variables +Inputs : Co-efficients of x and y in a pair of equations, Dependents +Outputs : Values of x and y +''' + +def solve(x_coefficient_1: float, y_coefficient_1: float, dependent_1: float, x_coefficient_2: float, y_coefficient_2: float, dependent_2: float) -> list: + ''' + >>> solve(4,5,20,1,2,13) + [-8.333333333333332, 10.666666666666666] + ''' + import numpy + coefficients = numpy.array([ [x_coefficient_1, y_coefficient_1], [x_coefficient_2, y_coefficient_2] ]) + dependents = numpy.array([dependent_1, dependent_2]) + answers = numpy.linalg.solve(coefficients, dependents) + return list(answers) + +if __name__ == '__main__': + from doctest import testmod + testmod() From a6f1f05865c439102b6e8b114de9c0e561280455 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 15:55:41 +0530 Subject: [PATCH 2/7] Update linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py index 82cf3a96afd8..3705053dfa7e 100644 --- a/maths/linear_equations_in_two_variables.py +++ b/maths/linear_equations_in_two_variables.py @@ -4,7 +4,12 @@ Outputs : Values of x and y ''' -def solve(x_coefficient_1: float, y_coefficient_1: float, dependent_1: float, x_coefficient_2: float, y_coefficient_2: float, dependent_2: float) -> list: +def solve(x_coefficient_1: float, + y_coefficient_1: float, + dependent_1: float, + x_coefficient_2: float, + y_coefficient_2: float, + dependent_2: float) -> list: ''' >>> solve(4,5,20,1,2,13) [-8.333333333333332, 10.666666666666666] From af757e77ead829989f6921a1db247b8d089fdeb8 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:37:13 +0530 Subject: [PATCH 3/7] Update linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py index 3705053dfa7e..c75c2f104e45 100644 --- a/maths/linear_equations_in_two_variables.py +++ b/maths/linear_equations_in_two_variables.py @@ -4,21 +4,26 @@ Outputs : Values of x and y ''' -def solve(x_coefficient_1: float, - y_coefficient_1: float, - dependent_1: float, - x_coefficient_2: float, - y_coefficient_2: float, - dependent_2: float) -> list: - ''' - >>> solve(4,5,20,1,2,13) - [-8.333333333333332, 10.666666666666666] - ''' - import numpy - coefficients = numpy.array([ [x_coefficient_1, y_coefficient_1], [x_coefficient_2, y_coefficient_2] ]) - dependents = numpy.array([dependent_1, dependent_2]) - answers = numpy.linalg.solve(coefficients, dependents) - return list(answers) +def solve( + x_coefficient_1: float, + y_coefficient_1: float, + dependent_1: float, + x_coefficient_2: float, + y_coefficient_2: float, + dependent_2: float, +) -> list: + """ + >>> solve(4,5,20,1,2,13) + [-8.333333333333332, 10.666666666666666] + """ + import numpy + + coefficients = numpy.array( + [[x_coefficient_1, y_coefficient_1], [x_coefficient_2, y_coefficient_2]] + ) + dependents = numpy.array([dependent_1, dependent_2]) + answers = numpy.linalg.solve(coefficients, dependents) + return list(answers) if __name__ == '__main__': from doctest import testmod From 97b868ec456440f83c7e2df8482155c5d3b3c72e Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:39:03 +0530 Subject: [PATCH 4/7] Update linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py index c75c2f104e45..ea219b594fd5 100644 --- a/maths/linear_equations_in_two_variables.py +++ b/maths/linear_equations_in_two_variables.py @@ -1,8 +1,8 @@ -''' +""" Solves linear equations in two variables Inputs : Co-efficients of x and y in a pair of equations, Dependents Outputs : Values of x and y -''' +""" def solve( x_coefficient_1: float, @@ -25,6 +25,6 @@ def solve( answers = numpy.linalg.solve(coefficients, dependents) return list(answers) -if __name__ == '__main__': +if __name__ == "__main__": from doctest import testmod testmod() From ccc8621ded3456fe1cfec11632a815230b59fccf Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:40:26 +0530 Subject: [PATCH 5/7] Update linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py index ea219b594fd5..b4535a5e5f36 100644 --- a/maths/linear_equations_in_two_variables.py +++ b/maths/linear_equations_in_two_variables.py @@ -27,4 +27,5 @@ def solve( if __name__ == "__main__": from doctest import testmod + testmod() From cb1dbeec6280838af9cf6317a472b4d775eb543c Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:43:53 +0530 Subject: [PATCH 6/7] Update linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py index b4535a5e5f36..897bc5a6f8e7 100644 --- a/maths/linear_equations_in_two_variables.py +++ b/maths/linear_equations_in_two_variables.py @@ -26,6 +26,6 @@ def solve( return list(answers) if __name__ == "__main__": - from doctest import testmod + from doctest import testmod - testmod() + testmod() From 6930b65d576319135317417d1d93c36499cb0338 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:47:27 +0530 Subject: [PATCH 7/7] Update linear_equations_in_two_variables.py --- maths/linear_equations_in_two_variables.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maths/linear_equations_in_two_variables.py b/maths/linear_equations_in_two_variables.py index 897bc5a6f8e7..02507946a111 100644 --- a/maths/linear_equations_in_two_variables.py +++ b/maths/linear_equations_in_two_variables.py @@ -4,6 +4,7 @@ Outputs : Values of x and y """ + def solve( x_coefficient_1: float, y_coefficient_1: float, @@ -25,6 +26,7 @@ def solve( answers = numpy.linalg.solve(coefficients, dependents) return list(answers) + if __name__ == "__main__": from doctest import testmod