I need to solve a system of n equations with respect to n unknowns $x$. Each equation is:
$\sum_{j=1}^m A_{ij}\sum_{i}^n B_{ij}x_{i} + d_{i}x_i=c_i,$ for $i = 1,\ldots,n$
Expanding the summations with $m=4$ and $n=3$ the system can be written as
$$\begin{cases} \sum_{j=1}^4 A_{1j}B_{1j}x_1 + \sum_{j=1}^4 A_{1j}B_{2j}x_2+\sum_{j=1}^4 A_{1j}B_{3j}x_3 +d_1x_1 = c_1\\ \sum_{j=1}^4 A_{2j}B_{1j}x_1 + \sum_{j=1}^4 A_{2j}B_{2j}x_2+\sum_{j=1}^4 A_{2j}B_{3j}x_3 +d_2x_2 = c_2\\ \sum_{j=1}^4 A_{3j}B_{1j}x_1 + \sum_{j=1}^4 A_{3j}B_{2j}x_2+\sum_{j=1}^4 A_{3j}B_{3j}x_3 +d_3x_3 = c_3 \end{cases} $$ I've found the solutions by substitution, solving the third equation with respect to $x_3$ and plugging the solution in the second equation, then solving the second with respect to $x_2$ and plugging these two solutions into the first. Hence I got, $$\begin{align} x_1 =& K^{-1}\left(c1-\left(\sum_{j=1}^4 A_{1j}B_{2j}- \sum_{j=1}^4A_{1j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}\sum_{j=1}^4A_{3j}B_{2j}\right)Z^{-1}\\ \left( c_2 - \sum_{j=1}^4A_{2j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}c_3\right) - \sum_{j=1}^4A_{1j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}c_3\right), \end{align} $$ $$\begin{align} x_2 =& Z^{-1}\left(c_2 - \sum_{j=1}^4A_{2j}B_{1j}x_1 - \sum_{j=1}^4A_{2j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1} \left(c_3 - \sum_{j=1}^4A_{3j}B_{1j}x_1\right)\right), \end{align}$$ and $$\begin{align} x_3 =& \left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1} \left(c_3 - \sum_{j=1}^4A_{3j}B_{1j}x_1 - \sum_{j=1}^4A_{3j}B_{2j}x_2\right), \end{align}$$ where $$Z=\sum_{j=1}^4A_{2j}B_{2j}-\sum_{j=1}^4A_{2j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}\sum_{j=1}^4A_{3j}B_{2j}$$
$$ \begin{align} K=&\sum_{j=1}^4A_{1j}B_{1j} +d_1 - \left( \sum_{j=1}^4A_{1j}B_{2j}- \sum_{j=1}^4A_{1j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}\sum_{j=1}^4A_{3j}B_{2j}\right)Z^{-1}\\ &\left( \sum_{j=1}^4A_{2j}B_{1j}- \sum_{j=1}^4A_{2j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}\sum_{j=1}^4A_{3j}B_{1j}\right)\\ & - \sum_{j=1}^4A_{1j}B_{3j}\left(\sum_{j=1}^4A_{3j}B_{3j}+d_3\right)^{-1}\sum_{j=1}^4A_{3j}B_{1j} \end{align}$$ Do you think this is the right procedure? Do you have any clue on how I can generalise the solutions for a generic n? Any help is appreciated.