Mathematics for Machine Learning - Day 4
Tags: learning, machinelearning, beginners, tutorial
Published: 2024-07-11 17:11:16


![Particular and General Solutions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/da6xhn8zhv220r6x0j4v.jpg)

## Particular and General Solutions
Ever wonder, if there's an equation with two or more variables that aren't known and there's not enough information to use basic elimination method? Fear not, there's a solution.

Also, this topic will only discuss on depth regarding particular and general solutions as I found that it takes me even more than an hour to really understand this and I find it very fascinating :D

### Particular Solutions
When a system has more than one solution, it's called a particular/special solution. One of the solution is if there are columns with only ones and zeros, the position of ones are unique in rows and columns, and ones are contained in all the rows.

#### Example:
{% katex %}
Ax = B
{% endkatex %}

{% katex %}
\begin{pmatrix}
1 & 0 & 8 & 0 & -4 \\\
0 & 1 & 2 & 0 & -12 \\\
0 & 0 & 4 & 1 & 7
\end{pmatrix}
\begin{pmatrix}
x_1 \\\
x_2 \\\
x_3 \\\
x_4 \\\
x_5
\end{pmatrix} = \begin{pmatrix}
42 \\\
8 \\\
12
\end{pmatrix}
{% endkatex %}

Now, you might find this to be impossible to solve, but let's break it down each matrix at a time.

##### Take a look at matrix A:
{% katex %}
A = \begin{pmatrix}
1 & 0 & 8 & 0 & -4 \\\
0 & 1 & 2 & 0 & -12 \\\
0 & 0 & 4 & 1 & 7
\end{pmatrix}
{% endkatex %}

you'll find that the 1st, 2nd, and 4th column if isolated becomes an identity matrix or as I've stated before, a unique ones in all rows and zeros.
{% katex %}
A(Reordered) = \begin{pmatrix}
1 & 0 & 0 & 8 & -4 \\\
0 & 1 & 0 & 2 & -12 \\\
0 & 0 & 1 & 4 & 7
\end{pmatrix}
{% endkatex %}

##### While B can become be decoupled to each row:

{% katex %}
\begin{pmatrix}
42 \\\
8 \\\
12
\end{pmatrix} = 42 \begin{pmatrix}
1 \\\
0 \\\
0
\end{pmatrix} + 8 \begin{pmatrix}
0 \\\
1 \\\
0
\end{pmatrix} + 12 \begin{pmatrix}
0 \\\
0 \\\
1
\end{pmatrix}
{% endkatex %}

##### Meaning:
If we ignore the 3rd and 5th column entirely, we can find the particular solution!

{% katex %}
\begin{pmatrix}
1 & 0 & 8 & 0 & -4 \\\
0 & 1 & 2 & 0 & -12 \\\
0 & 0 & 4 & 1 & 7
\end{pmatrix}
\begin{pmatrix}
42 \\\
8 \\\
0 \\\
12 \\\
0
\end{pmatrix} = \begin{pmatrix}
42 \\\
8 \\\
12
\end{pmatrix}
{% endkatex %}

{% katex %}
\begin{pmatrix}
42 + 0 + 0 + 0 + 0 \\\
0 + 8 + 0 + 0 + 0 \\\
0 + 0 + 0 + 12 + 0
\end{pmatrix} = \begin{pmatrix}
42 \\\
8 \\\
12
\end{pmatrix}
{% endkatex %}


Congratulations! You've found the particular solution!
{% katex %}
\therefore \begin{pmatrix}
x_1 \\\
x_2 \\\
x_3 \\\
x_4 \\\
x_5
\end{pmatrix} = 
\begin{pmatrix}
42 \\\
8 \\\
0 \\\
12 \\\
0
\end{pmatrix}
{% endkatex %}

---

## General Solutions
Now this is where it took me an hour to understand what they were saying, so let's dive into it.

General solutions are basically adding in 0 to the equation. Instead of
{% katex %}
Ax = B
{% endkatex %}
We'll be adding in 0 to the first section based on the amount of non-identity matrix related columns (In our case it's two, the 3rd and 5th column)

{% katex %}
A x + \lambda_1 \cdot 0 + \lambda_2 \cdot 0 = B
{% endkatex %}

The lambda is used because since it's multiplied by 0, any scaler added will still remain zero, so it covers all values added to it.

### First General Solution (3rd Row)

{% katex %}
\begin{pmatrix}
8 \\\
2 \\\
4
\end{pmatrix}
{% endkatex %}

#### Using the same decouple method as before:

{% katex %}
\begin{pmatrix}
8 \\\
2 \\\
4
\end{pmatrix} = 8 \begin{pmatrix}
1 \\\
0 \\\
0
\end{pmatrix} + 2 \begin{pmatrix}
0 \\\
1 \\\
0
\end{pmatrix} + 4 \begin{pmatrix}
0 \\\
0 \\\
1
\end{pmatrix}
{% endkatex %}

You'll remember that this decouple when added to x in the order of the identity matrix will become the answer. Meaning:

{% katex %}
\text{If } 
\begin{pmatrix}
x_1 \\\
x_2 \\\
x_3 \\\
x_4 \\\
x_5
\end{pmatrix} = 
\begin{pmatrix}
8 \\\
2 \\\
0 \\\
4 \\\
0
\end{pmatrix}
\text{, then } 
B = 
\begin{pmatrix}
8 \\\
2 \\\
4
\end{pmatrix}
{% endkatex %}

#### So how do I make it zero?
Easy! the column that's associated to the matrix (In our case is the 3rd) we make it -1.

{% katex %}
\begin{pmatrix}
x_1 \\\
x_2 \\\
x_3 \\\
x_4 \\\
x_5
\end{pmatrix} = 
\begin{pmatrix}
8 \\\
2 \\\
-1 \\\
4 \\\
0
\end{pmatrix}
{% endkatex %}

#### Here's the proof

{% katex %}
\begin{pmatrix}
1 & 0 & 8 & 0 & -4 \\\
0 & 1 & 2 & 0 & -12 \\\
0 & 0 & 4 & 1 & 7
\end{pmatrix}
\begin{pmatrix}
8 \\\
2 \\\
-1 \\\
4 \\\
0
\end{pmatrix}
{% endkatex %}

{% katex %}
\begin{pmatrix}
8 + 0 - 8 + 0 + 0 \\\
0 + 2 - 2 + 0 + 0 \\\
0 + 0 - 4 + 4 + 0
\end{pmatrix} = 
\begin{pmatrix}
0 \\\
0 \\\
0
\end{pmatrix}
{% endkatex %}

### Now we add the first answer to our general solution!


{% katex %}
A x + \lambda_1 \cdot 
\begin{pmatrix}
8 \\\
2 \\\
-1 \\\
4 \\\
0
\end{pmatrix} + \lambda_2 \cdot 0 = B
{% endkatex %}

### Second General Solution (5th Row)

####  Surprize Quiz!
Now that you know how to find the equation for the general solution, try finding the second one yourself! The answer is at the bottom so you can check if you're correct or not.

{% katex %}
\begin{pmatrix}
-4 \\\
-12 \\\
7
\end{pmatrix}
{% endkatex %}

---
### The full equation.
We've found the particular solutions that's needed to create the general solution!

For clarity, let's discuss what we did:
1. Find the particular solution to Ax = B
2. Find all the solutions to Ax = 0
3. Add steps one and two together

With these steps finished, congratulations! you've become familiar with particular and general solutions. From here on out, you know that there are cases where large unknown variables with little equations can be solved with the right conditions.

#### The general solution

{% katex %}
\left\( x \in \mathbb{R}^5 \mid x = 
\begin{pmatrix}
42 \\\
8 \\\
0 \\\
12 \\\
0
\end{pmatrix} + \lambda_1 
\begin{pmatrix}
8 \\\
2 \\\
-1 \\\
4 \\\
0
\end{pmatrix} + \lambda_2 
\begin{pmatrix}
-4 \\\
-12 \\\
0 \\\
7 \\\
-1
\end{pmatrix}, \; \lambda_1, \lambda_2 \in \mathbb{R} \right\)
{% endkatex %}


P.S. The book notated using large curly brackets `{` but it returned an error on Dev.to so I'm using normal brackets (It's working on my website though!). Also, hope you got the answer right :D

---

## Acknowledgement
I can't overstate this: I'm truly grateful for this book being open-sourced for everyone. Many people will be able to learn and understand machine learning on a fundamental level. Whether changing careers, demystifying AI, or just learning in general, this book offers immense value even for _fledgling composer_ such as myself. So, Marc Peter Deisenroth, A. Aldo Faisal, and Cheng Soon Ong, thank you for this book.

Source:
Deisenroth, M. P., Faisal, A. A., &#38; Ong, C. S. (2020). Mathematics for Machine Learning. Cambridge: Cambridge University Press.
https://mml-book.com