# What is the pattern and the solution to this system of equations?

I would like to find the general solution to the following system of equations:

$$x_1 + k_1 + \sum_{i=1}^N A_{1,i}x_i=0$$ $$x_2 + k_2 + \sum_{i=1}^N A_{2,i}x_i=0$$ $$\vdots$$ $$x_N + k_N + \sum_{i=1}^N A_{N,i}x_i=0$$

where $$k_j$$ and $$A_{j,i}$$ are known constants, and $$x_j$$ are the unknown variables. This system has $$N$$ equations with $$N$$ unknown variables. However, $$N$$ in my case is at least $$50$$. I want to find the pattern for solving this system numerically in Matlab using recursion and loops. I have a feeling an algorithm can be constructed, but I can't find the pattern. Here is what I did.

I solved this problem for $$N=1$$, $$N=2$$ and $$N=3$$. For $$N = 1$$ the solution is:

$$x_1 = -{k_1 \over 1 + A_{1,1}} \tag 1$$

Also, for $$N = 2$$ the solution is:

$$x_1 = { -(1 + A_{2,2}) k_1 + A_{1,2} k_2 \over (1 + A_{1,1}) (1 + A_{2,2}) - A_{1,2} A_{2,1}} \tag 2$$

$$x_2 = { A_{2,1} k_1-(1 + A_{1,1}) k_2 \over (1 + A_{1,1}) (1 + A_{2,2}) - A_{1,2} A_{2,1} } \tag 3$$

And the solution for $$N = 3$$ is:

$$x_1 = {-\big( (1 + A_{2,2}) (1 + A_{3,3}) - A_{2,3} A_{3,2} \big) k_1 + (A_{1,2} (1 + A_{3,3}) - A_{1,3} A_{3,2}) k_2 + (A_{1,3} (1 + A_{2,2}) - A_{1,2} A_{2,3}) k_3 \over C} \tag 4$$

$$x_2 = { (A_{2,1} (1 + A_{3,3}) - A_{2,3} A_{3,1}) k_1 -\big( (1 + A_{1,1}) (1 + A_{3,3}) - A_{1,3} A_{3,1} \big) k_2 + (A_{2,3} (1 + A_{1,1}) - A_{1,3} A_{2,1}) k_3 \over C} \tag 5$$ $$x_3 = { (A_{3,1} (1 + A_{2,2}) - A_{2,1} A_{3,2}) k_1 + (A_{3,2} (1 + A_{1,1}) - A_{1,2} A_{3,1}) k_2 -\big( (1 + A_{1,1}) (1 + A_{2,2}) - A_{1,2} A_{2,1} \big) k_3 \over C} \tag 6$$

where:

$$C = (1 + A_{1,1}) (1 + A_{2,2}) (1 + A_{3,3}) - (1 + A_{1,1}) A_{2,3} A_{3,2} - (1 + A_{2,2}) A_{1,3} A_{3,1} - (1 + A_{3,3}) A_{1,2} A_{2,1} + A_{1,2} A_{2,3} A_{3,1} + A_{3,2} A_{2,1} A_{1,3} \tag 7$$

Unfortunately, I can't seem to notice the general pattern. The only thing I do notice is that there might be two separate patterns involved. One for the numerator and one for the denominator. I would like to ask for help.

In summary, I would like to numerically solve this system of equations, but I need to construct an algorithm for that based on the pattern I can't seem to notice. My question is, what is the general solution for $$x_n$$, where $$n \in \{1, 2, ... N\}$$, and $$N \in \Bbb{N}$$? If there is no general solution, how can I construct the algorithm I need using recursions and loops (if it can be done at all)?

NOTE: I also tried to solve for $$N=4$$, but the solution for one variable got two pages long, so I couldn't see the right way to group the terms in a way that would help find the general pattern. I will write it down here, but I doubt it is of any use:

$$x_1 = {Q_1 k_1 + Q_2 Q_2 + Q_3 k_3 + Q_4 k_4 \over D} \tag 8$$

$$Q_1 = - \Big( (1 + A_{3,3}) (1 + A_{4,4}) - A_{3,4} A_{4,3} \Big)f_1 \tag 9$$

$$Q_2 = \Big ( (1 + A_{3,3}) (1 + A_{4,4}) - A_{3,4} A_{4,3} \Big) f_3 \tag {10}$$

$$Q_3 = \Big( (1 + A_{4,4}) A_{1,3} - A_{1,4} A_{4,3} \Big)f_1 - \Big( (1 + A_{4,4}) A_{2,3} - A_{2,4} A_{4,3} \Big) f_3 \tag {11}$$

$$Q_4 = \Big( (1 + A_{3,3}) A_{1,4} - A_{1,3} A_{3,4} \Big)f_1 - \Big( (1 + A_{3,3}) A_{2,4} - A_{2,3} A_{3,4} \Big)f_3 \tag {12}$$

$$f_1 = (1 + A_{2,2}) (1 + A_{3,3}) (1 + A_{4,4}) - (1 + A_{2,2}) A_{3,4} A_{4,3} - (1 + A_{3,3}) A_{2,4} A_{4,2} - (1 + A_{4,4}) A_{2,3} A_{3,2} + A_{2,3} A_{3,4} A_{4,2} + A_{2,4} A_{4,3} A_{3,2} \tag{13}$$

$$f_2 = (1 + A_{1,1}) (1 + A_{3,3}) (1 + A_{4,4}) - (1 + A_{1,1}) A_{3,4} A_{4,3} - (1 + A_{3,3}) A_{1,4} A_{4,1} - (1 + A_{4,4}) A_{1,3} A_{3,1} + A_{1,4} A_{4,3} A_{3,1} + A_{1,3} A_{3,4} A_{4,1} \tag{14}$$

$$f_3 = (1 + A_{3,3}) (1 + A_{4,4}) A_{1,2} - (1 + A_{3,3}) A_{1,4} A_{4,2} - (1 + A_{4,4}) A_{1,3} A_{3,2} - A_{1,2} A_{3,4} A_{4,3} + A_{1,3} A_{3,4} A_{4,2} + A_{1,4} A_{4,3} A_{3,2} \tag {15}$$

$$f_4 = -(1 + A_{3,3}) (1 + A_{4,4}) A_{2,1} + (1 + A_{3,3}) A_{2,4} A_{4,1} + (1 + A_{4,4}) A_{2,3} A_{3,1} + A_{2,1} A_{3,4} A_{4,3} - A_{2,3} A_{3,4} A_{4,1} - A_{2,4} A_{3,1} A_{4,3} \tag{16}$$

$$D = f_1 f_2 + f_3 f_4 \tag {17}$$

If we denote
\begin{align} &a_{i,j} = \cases{A_{i,j} &if i=j \\ A_{i,j} +1 &if i\ne j } \hspace{1cm} &\forall 1\le i,j \le N \\ &b_{i} =-k_i &\hspace{1cm} \forall 1\le i \le N \end{align} then the problem is simply equivalent to solve a system of linear equations: $$\sum_{i=1}^N a_{i,j}x_j=b_i \hspace{1cm} \forall 1\le i \le N \tag{1}$$

Without any further information about $$(A_{i,j})_{1\le i,j \le N}$$, only general solutions are available.

Let us denote $$\mathbf{a} := (a_{i,j})_{i,j} \in \mathbb{R}^{N\times N}$$ the invertible matrix, $$\mathbf{x} := (x_1,..,x_N)'$$ and $$\mathbf{b} := (b_1,..,b_N)'$$ then the system of linear equations $$(1)$$ can be expressed in matrix form as follows: $$\mathbf{a}\cdot \mathbf{x} = \mathbf{b}$$ As the matrix $$\mathbf{a}$$ is invertible, mathematically, the solution $$\mathbf{x}$$ is equal to $$\mathbf{x} = \mathbf{a}^{-1}\cdot \mathbf{b} \tag{2}$$

Remark: numerically, there are several methods for solving the system of linear equations. With only available information of $$N$$ (and not $$\mathbf{a}$$ or $$\mathbf{b}$$) , I think this answer is useful.

• I just noticed in your link that I can construct a matrix form of my problem $[A] \vec x=\vec b$. My matrix is square, and full rank, so I can just use its inverse to solve my problem: $\vec x = [A]^{-1} \vec b$. Can you demonstrate this in your answer so I can accept it? Thank you a lot! Commented Jan 13 at 23:16
• @NikolaRistic I add some other information. Hope that helps!
– NN2
Commented Jan 13 at 23:45