You are on page 1of 8

Term Paper

SOLUTIONS OF LINEAR
EUATIONS IN TWO VARIABLES
USING PYTHON
Introduction To Python Programming

Name:-Adarsh Tiwari
Roll No:- 19120007
Semester- 5th
Sub :- Introduction To Python Programming

NIT Raipur
B-Tech
Abstract-
In this Paper we are going to discuss about solutions of linear equations by using
python. Linear equations are having all variables as degree 1 and mainly we study 2
types of linear equations i.e. linear equations in 2 variables and 3 variables. Solutions
of linear equations can be found out by making 3 matrix one of coefficients of
variables and other matrix is of variables and making it equal to matrix of constants
i.e. Ax = B for finding solutions. In python we use NumPy and linear algebra to solve
the matrix. So, in this way we find out solutions of linear equations using python.
Keywords- Linear Equations, python, Variables, matrix, cofficients, NumPy.

1.Introduction –
Linear Equations: - A equation having graph as a straight line is known as linear
Equation, also if degree of all variable is one is also known as linear equation.
Equations of this are ax+ by + c = 0, where “a” and “b” ≠ 0.
A linear Equations are of types: -
 Linear Equations in 2 variables
Example: - 4x +5y =7
5x +2y = 8,
x/4 + y/6=7,
3x+ 2y -9 =0
& y= 3x + 8
 Linear Equations in 3 variables
Example: - 4x +5y +3z=7
5x +2y + 6z= 8,
x/4 + y/4 + z/4 =7,
x+ y +z =9
Graph Of linear Equations: - Graph 2 – x/4 + y /8 =1
Graph 1 – 5x + 6y = 30

Graph 3 = 3x + 2y -9 = 0

Page 1 of 9
Graph 4 - y= 3x + 8
Graph 3 = 3x +2y -9 =0

Now Graph in 3 variables, these graphs are like a plane.

Graph 1 – 3x + 5y +4z = 60

Page 2 of 9
Graph 2 - ((x)/ (4)) +((y)/ (4)) +((z)/ (4)) =7

Page 3 of 9
2.Solutions of Linear Equations: -
For 2 variables-
In 2 variables there are 2 or more equations are given we had to find out the point or
the value of x and y which satisfy all the given equations known as Solution of linear
equations.
In Graph where graphs intersect each other that point is known as solution of those
equations.
Example: - let Given Equations are 3x + 5y + 8 = 0
&6x + 5y + 20 =0

In above Graph solution is x= -4 & y= 0.8 are solution of linear Equations.

Page 4 of 9
For 3 Variables: - x + y + z = 28
& 4x + 5y + 3z = 60

This point of intersections of planes is knowns as solutions of linear equations the


values of x, y and z at intersection point is known as Solution of Linear Equations.
3.Matrix Form To find out Solutions –
Equations are given to find out solutions like for ex Equ 1- 3x + 5y = 15 and Equ
2- 7x + 4y = 28. We make 3 matrix, matrix 1 of coefficients of variables and matrix 2
of variables and equate it to matrix 3 of constants.
So here it is made like Ax = B A= {3 ,5} B= {15} and Ax = B.
{7,4} {28}

We solve this matrix and whatever values comes is solutions of linear Equations .

Page 5 of 9
In 3 variables in the same way 3 matrix are formed and we solve it to get solutions of
matrix. Equations of 3 variables are 2x + y -3 =-4 ,4x-2y+z =9 ,3x + 5y -2z =5.

4.Solutions of Linear Equations using Python-


We are using NumPy in which linear algebra is used to solve matrix Equations,
Equations are 2x + y -3z = -4, 4x -2y +z =9 and 3x + 5y -2z = 5.

Code and Output: -


import numpy as np
A = np.array([[2,1,-3],[4,-2,1],[3,5,-2]])
print (A)
ouput= [[2 1 -3]
[4 -2 1]
[3 5 -2]]

import numpy as np

A = np.array([[2,1,-3],[4,-2,1],[3,5,-2]])

b = np.array ([-4,9,5])

y=np.linalg.solve(A,b)

print(y)

output= [2.207, -1.275, -2.374]

So, we get solutions as x= 2.207, y = -1.275 and z = -2.374


And others Equations are - 4x +5y +3z=7 ,5x +2y + 6z= 8 & x + y + z =28
Matrix form of Equations is-

Page 6 of 9
Code and Output: -
import numpy as np
A = np.array([[4,5,3],[5,2,6],[1,1,1]])
print (A)
ouput= [[4 5 3]
[5 2 6]
[1 1 1]]

import numpy as np

A = np.array([[4,5,3],[5,2,6],[1,1,1]])

b = np.array ([7,8,28])

y=np.linalg.solve(A,b)

print(y)

output= [-314.,118.5, 223.5]

So, we get solutions as x = -314 ,y= 118.5 and z = 223.5

5.Conclusion-
Using python make it very easier to solve the system of linear Equations in 3
variables we use the format Ax=b. Programming make it very easy to solve these
heavy cumbersome linear equations and to get solutions very fast within seconds
while solving manually accuracy is also a problem but through this, we get very
accurate answers. Solution of Linear equations are used in various parts in Mathmatics
with the help of python you can get these solutions very easily.

6.Reference-
1. (2021) Youtube.com. Available at: https://www.youtube.com/watch?v=0WOY0LcLjUE
(Accessed: 22 October 2021).
2. (2021) Jusst.org. Available at: https://jusst.org/wp-content/uploads/2021/07/A-STUDY-OF-
SOLVING-SYSTEM-OF-LINEAR-EQUATION-USING-DIFFERENT-METHODS-AND-ITS-REAL-LIFE-
APPLICATIONS.pdf (Accessed: 22 October 2021).
3. (2021) Globaljournals.org. Available at: https://globaljournals.org/GJCST_Volume15/4-System-
of-Linear-Equations.pdf (Accessed: 22 October 2021).
4. How do you solve linear equations in three variables? (with example) (2021). Available at:
https://byjus.com/jee-questions/how-to-you-solve-linear-equations-in-three-variables/
(Accessed: 22 October 2021)

Page 7 of 9

You might also like