Luogu3389 【模板】高斯消元法

题目传送门

算法分析

高斯消元,是求解\(n\)\(n\)\(1\)次方程组的算法,一般情况下时间复杂度为\(O(n^3)\)

我们把这\(n\)个方程组看成一个\(n\times (n+1)\)的矩阵。以样例为例:

\[ \left( \begin{matrix} {{x}_{1}} & 3\times {{x}_{2}} & 4\times {{x}_{3}} \\ {{x}_{1}} & 4\times {{x}_{2}} & 7\times {{x}_{3}} \\ 9\times {{x}_{1}} & 3\times {{x}_{2}} & 2\times {{x}_{3}} \\ \end{matrix} \right)=\left( \begin{matrix} 5 \\ 3 \\ 2 \\ \end{matrix} \right) \]

我们把答案也写成矩阵的形式,不难发现:我们的目标矩阵应该形如下面
\[\left( \begin{matrix} {{x}_{1}} & 0 & 0 \\ 0 & {{x}_{2}} &0 \\ 0& 0& {{x}_{3}} \\ \end{matrix} \right)=\left( \begin{matrix} -\frac{37}{38} \\ \frac{197}{38} \\ -\frac{91}{38} \\ \end{matrix} \right) \]

猜你喜欢

转载自www.cnblogs.com/ZigZagKmp/p/11488474.html