+2 votes
in Programming Languages by (73.8k 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

+1 vote
by (349k points)
selected by
 
Best answer

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.])


...