+2 votes
in Programming Languages by (59.5k points)
retagged by
How to solve the system of equations using Numpy library in Python?

e.g. for the following system of equations, x1=2, x2=1, x3=2

4x1 + 5x2 + 6x3 = 25
2x1 + 3x2 + 4x3 = 15
4x1 + 5x2 + 2x3 = 17

1 Answer

0 votes
by (233k points)

You can use the solve() function of Linear algebra module of numpy to solve the system of equations. For your set of equations, you can try the following code:

>>> import numpy as np
>>> a = np.array([[4,5,6], [2,3,4], [4,5,2]])
>>> b = np.array([25,15,17])
>>> x = np.linalg.solve(a, b)
>>> x
array([2., 1., 2.])


...