Solving linear equations
In this section, you will learn how to solve linear equations by using the linalg.solve()
method. When you have a linear equation to solve, as in the form

, in simple cases you can just calculate the inverse ofAand then multiply it by Bto get the solution, but whenAhas a high dimensionality, that makes it very hard computationally to calculate the inverse ofA. Let's start with an example of three linear equations with three unknowns, as follows:



So, these equations can be formalized as follows with matrices:

Then, our problem is to solve

. We can calculate the solution with a plain vanilla NumPy without using linalg.solve()
. After inverting the A matrix, you will multiply with B in order to get results for x. In the following code block, we calculate the dot product for the inverse matrix of A and B in order to calculate

:

In [44]: A = np.array([[2, 1, 2], [3, 2, 1], [0, 1, 1]]) A Out[44]: array([[2, 1, 2], [3, 2, 1], [0, 1...