Solving large linear systems with NumPy
The last example should make it clear that Gaussian elimination will work for any linear system to reduce it to RREF form, but this 3-equation, 3-variable system required a significant amount of effort to solve, and things will only become more complex for larger systems, so the more practical way to do it is to use existing algorithms. In this section, we will learn how to use some methods with NumPy to accomplish this task.
A Python function for solving systems of linear equations Ax = b is available in NumPy named numpy.linalg.solve
, which works for square, consistent systems. That is, it finds solutions for all linear systems that have unique solutions.
Typically, the function uses a version of Gaussian elimination just as we have done by hand, but it is a very smart function. First, the function chooses the order of calculations carefully to optimize its speed. Second, if the function detects that A has a special structure (such as...