During my graduation, I developed interest in machine learning and started studying about it. I realized most part of machine learning, if not all, is mathematics. Because the math I studied in my university got hazy with time, I decided to start it all over again and study the mathematics required for machine learning. [For the curious out there, the book I refer to for machine learning math is Mathematics for Machine Learning. Yes, it is free of cost and you can download it here].

In this article, I am going to talk about system of linear equations and how it can be useful in solving day to day problems. Ultimately, we will solve the system in python.

## Introduction to System of Linear Equations

System of linear equations help us solve many problems. In the book, they have mentioned about a company producing some products and the required resources, and ultimately generating a system of linear equations for that situation. I am going to consider the same thing but in a bit more practical way.

I am going that an automobile company is producing 3 items: engine, gearbox and suspension system. Annually, it produces \(x, y\) and \(z\) number of units respectively. To manufacture these products, it utilizes resources like steel, lubricating oil and bolts. The question is, how much resources should the company order so that nothing goes as waste.

Say it takes 5 units, 2 units and 3 units of \(b1\) (or steel) to produce 1 unit of each of the products. Hence the total number of steel units required is \(b1\). This can be summarized as the following equation:

\(5x+ 2y + 3z = b1\)

Similarly, \(2, 3\) and \(4\) units of lubricating oil are required for production of 1 unit of each of the products. Therefore the total units of lubricating oil required will be:

\(2x+ 3y + 4z = b2\)

Following the same procedure for bolts (10 bolts for 1 unit of engine, 12 for a unit of gear box and 8 for a unit of suspension system), we get:

\(10x+ 12y + 8z = b3\)

To summarize, we formed 3 linear equations for 3 different resources. Putting these equations together, we get:

\(5x+ 2y + 3z = b1\)

\(2x+ 3y + 4z = b2\)

\(10x+ 12y + 8z = b3\)

Vectorizing the system of linear equations, we get:

\(\begin{bmatrix}5x + 2y + 3z\\ 2x+ 3y + 4z\\ 10x+ 12y + 8z \end{bmatrix}=

\begin{bmatrix}b1 \\ b2 \\ b3 \end{bmatrix}\)

The above equation can further be simplied as follows:

\(\begin{bmatrix}5 & 2 & 3\\ 2 & 3 & 4\\ 10 & 12 & 8 \end{bmatrix} \cdot \begin{bmatrix} x & y & z \end{bmatrix}= \begin{bmatrix}b1 \\ b2 \\ b3 \end{bmatrix}\)

\(\begin{equation} A \cdot X = B \end{equation}\)

This shows that with the information of the number of resources required per unit of a product and the number of products to be produced is known, the total number of resources can be determined such that there is no waste. Now its time to implement the above equation in Python.

## The Code

I am going to utilize `numpy`

library for this exercise. The matrix with the number of resources required per unit of a product will be stored in A, the total number of products produced annually as X and the total number of resources required will be the output.

```
import numpy as np
A = np.array([[5, 2, 3], [2, 3, 4], [10, 12, 8]])
```

Assuming that the company wants to produce 10 units of engine, 15 units of gearbox and 20 units of suspension systems:

`X = np.array([[10, 15, 20]])`

Because the shape of \(A\) is \((3, 3)\) and the shape of \(X\) is \((1, 3)\), we need to take the transpose of \(X\) for the dot product to take place.

`B = np.dot(A, X.T)`

### Output:

\(\begin{bmatrix} 140\\145\\440\end{bmatrix}\)

This shows that the company would require 140 units of steel, 145 units of lubricating oil and 440 units of bolts.

In this way, system of linear equations can be formed to solve simple tasks. Feel free to comment below if you have any feedback or feel like sharing your own experience.