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 of A and then multiply it by B to get the solution, but when A has a high dimensionality, that makes it very hard computationally to calculate the inverse of A. Let's start with an example of three linear equations with three unknowns, as follows:
![](https://static.packt-cdn.com/products/9781788993357/graphics/assets/df1cc562-7e5d-4f08-a064-2422ce4396cf.png)
![](https://static.packt-cdn.com/products/9781788993357/graphics/assets/d3c7d7f4-45b7-4f99-9140-96d85bd7eb26.png)
![](https://static.packt-cdn.com/products/9781788993357/graphics/assets/97486ea5-22df-4a72-8d10-20a0415182e1.png)
So, these equations can be formalized as follows with matrices:
![](https://static.packt-cdn.com/products/9781788993357/graphics/assets/46e30ae2-34f0-42d4-af84-332288db9ce6.png)
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
:
![](https://static.packt-cdn.com/products/9781788993357/graphics/assets/ef1be631-814e-4c87-97a2-37178f104461.png)
In [44]: A =...