System of equations and how to solve it
In this recipe, we will see how to solve system of equations and its applications.
Getting ready
Get the library and the numpy.linalg.solve
reference.
How to do it...
We have the following functions and parameters:
Parameters |
Coefficient matrix.
Ordinate or dependent variable values. |
Returns |
Solution to the system |
Raises |
If |
Note
Broadcasting rules apply; see the numpy.linalg
documentation for details. The solutions are computed using the LAPACK _gesv
routine it must be square and of full-rank, that is, all rows (or, equivalently, columns) must be linearly independent; if either is not true, use lstsq
for the least-squares best solution of the system/equation.
How it works...
Solve the system of equations 3 * x0 + x1 = 9 and x0 + 2 * x1 = 8:
a=np.array([[3,1],[1,2]])b=np.array([9...