Posts

Showing posts with the label systes

Solving a Linear Systes of Equations Using python

Image
Solving a Linear Systes of Equations Using python Solving linear systems of equations is straightforward using the scipy command linalg.solve . This command expects an input matrix and a right-hand-side vector. The solution vector is then computed. An option for entering a symmetrix matrix is offered which can speed up the processing when applicable. As an example, suppose it is desired to solve the following simultaneous equations: We could find the solution vector using a matrix inverse: However, it is better to use the linalg.solve command which can be faster and more numerically stable. In this case it however gives the same answer as shown in the following example: >>> import numpy as np >>> from scipy import linalg >>> A = np . array ([[ 1 , 2 ],[ 3 , 4 ]]) >>> A array([[1, 2], [3, 4]]) >>> b = np . array ([[ 5 ],[ 6 ]]) >>> b array([[5], [6]]) >>> linalg . inv ( A ) . dot ( b ) #slow array([[-4. ], ...