{"id":288059,"date":"2018-08-16T14:22:00","date_gmt":"2018-08-16T10:22:00","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288059"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288059","title":{"rendered":"\u041f\u043e\u0447\u0435\u043c\u0443 \u0413\u0430\u0443\u0441\u0441? (100 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0443\u0440\u0430\u0432\u043d\u043d\u0435\u043d\u0438\u0439)"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/418241\/\" class=\"post__text post__text-html js-mediator-article\">\u0427\u0442\u043e \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0441\u044f\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441 \u0442\u0440\u0435\u043c\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438? \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439. \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u0443 \u0413\u0430\u0443\u0441\u0441\u0430? <br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041e\u0431\u043e \u0432\u0441\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443<\/h3>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e. \u041f\u0443\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430: <\/p>\n<p><math>$$display$$\\left\\{ \\begin{aligned} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 = b_1,\\\\ a_{21}x_1 + a_{22}x_2 + a_{23}x_3 = b_2, \\\\ a_{31}x_1 + a_{32}x_2 + a_{33}x_3 = b_3. \\\\ \\end{aligned} \\right.$$display$$<\/math><\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0413\u0430\u0443\u0441\u0441\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u00ab\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0438\u00bb \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u043d\u0438\u0436\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438. \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <math>$inline$ \\dfrac{a_{21}}{a_{11}} $inline$<\/math> \u0438 \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0432\u0442\u043e\u0440\u043e\u0433\u043e (\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <math>$inline$ \\dfrac{a_{31}}{a_{11}} $inline$<\/math> \u0438 \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e). \u0422\u043e \u0435\u0441\u0442\u044c, \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:   <\/p>\n<p><math>$$display$$\\left\\{ \\begin{aligned} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 = b_1,\\\\ a_{22}&#8217;x_2 + a_{23}&#8217;x_3 = b_2&#8242;, \\\\ a_{32}&#8217;x_2 + a_{33}&#8217;x_3 = b_3&#8242;. \\\\ \\end{aligned} \\right.$$display$$<\/math><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0442\u043e\u0440\u043e\u0435 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <math>$inline$ \\dfrac{a_{32}&#8217;}{a_{22}&#8217;} $inline$<\/math> \u0438 \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e:   <\/p>\n<p><math>$$display$$\\left\\{ \\begin{aligned} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 = b_1,\\\\ a_{22}&#8217;x_2 + a_{23}&#8217;x_3 = b_2&#8242;, \\\\ a_{33}&#187;x_3 = b_3&#187;. \\\\ \\end{aligned} \\right.$$display$$<\/math><\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <math>$inline$x_3$inline$<\/math>, \u0437\u0430\u0442\u0435\u043c <math>$inline$x_2$inline$<\/math> \u0438 <math>$inline$x_1$inline$<\/math>.<\/p>\n<p>  \u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442: \u0430 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e? \u0427\u0442\u043e \u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <math>$inline$a_{11} = 0$inline$<\/math>? \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0413\u0430\u0443\u0441\u0441\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f? <\/p>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0439\u0434\u0435\u043c <math>$inline$\\max|a_{1j}|$inline$<\/math> \u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 <math>$inline$j$inline$<\/math>-\u0443\u044e \u0438 \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 (\u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f \u043e\u0431\u0449\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e <math>$inline$\\max |a_{1j}| = a_{13}$inline$<\/math>). \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 <math>$inline$a_{1j}=0$inline$<\/math> \u0431\u044b\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u043b\u044c \u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c. \u0418\u0442\u0430\u043a, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 3-\u0433\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<p>  \u041f\u043e\u0438\u0441\u043a\u043e\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 <math>$inline$k$inline$<\/math>-\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043a\u0430\u0442\u044c <math>$inline$\\max |a_{kj}|$inline$<\/math>, \u0437\u0430\u0442\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c <math>$inline$j$inline$<\/math>-\u0443\u044e \u0438 <math>$inline$k$inline$<\/math>-\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0438. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0413\u0430\u0443\u0441\u0441\u0430 \u0441 \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041c\u043e\u0436\u043d\u043e \u043d\u0430 <math>$inline$k$inline$<\/math>-\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043a\u0430\u0442\u044c <math>$inline$\\max |a_{ik}|$inline$<\/math>, \u0437\u0430\u0442\u0435\u043c \u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0436\u0435 \u043d\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u044b. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <math>$inline$\\alpha$inline$<\/math> (\u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445).<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c: <\/p>\n<pre><code class=\"java\">import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Locale; import java.util.Scanner;  public class GuassianEliminationSearchMainElementsAtString { \tpublic static void main(String[] args) throws IOException { \t\t \t\tScanner sc = new Scanner(new FileReader(&quot;input.txt&quot;)); \t\tsc.useLocale(Locale.US); \t\t \t\tint n = sc.nextInt(); \t\tdouble[][] a = new double[n + 1][n + 1]; \t\tdouble[] b = new double[n + 1]; \t\t \t\t\/\/ input \t\tfor (int i = 1; i &lt;= n; i++) {  \t\t\tfor (int j = 1; j &lt;= n; j++) { \t\t\t\ta[i][j] = sc.nextDouble(); \t\t\t} \t\t\tb[i] = sc.nextDouble(); \t\t}  \t\tint[] alpha = new int[n + 1]; \/\/ array of indices \t\tfor (int i = 1; i &lt;= n; i++) { \t\t\talpha[i] = i; \t\t}  \t\tfor (int m = 1; m &lt;= n; m++) { \t\t\tdouble max = Math.abs(a[m][m]); \t\t\tint count = m; \t\t\tfor (int i = m + 1; i &lt;= n; i++) { \t\t\t\tif (Math.abs(a[m][i]) &gt; max) { \/\/ search max elements at the string \t\t\t\t\tmax = Math.abs(a[m][i]); \t\t\t\t\tcount = i; \t\t\t\t} \t\t\t}  \t\t\tint tmp = alpha[m]; \/\/ swap strings \t\t\talpha[m] = alpha[count]; \t\t\talpha[count] = tmp;  \t\t\tfor (int i = m; i &lt;= n; i++) { \t\t\t\tdouble tmp2 = a[i][m]; \t\t\t\ta[i][m] = a[i][count]; \t\t\t\ta[i][count] = tmp2; \t\t\t}  \t\t\tfor (int i = m + 1; i &lt;= n; i++) { \/\/ guassian right stroke \t\t\t\tb[i] = b[i] - a[i][m] * b[m] \/ a[m][m]; \t\t\t\tfor (int j = m + 1; j &lt; n; j++) { \t\t\t\t\ta[i][j] = a[i][j] - a[i][m] * a[m][j] \/ a[m][m]; \t\t\t\t} \t\t\t}  \t\t} \/\/ for m   \t\tdouble[] x = new double[n+1]; \t\tfor (int i = n; i &gt;= 1; i--) { \/\/ guassian back stroke \t\t\tdouble sum = 0; \t\t\tfor (int j = i + 1; j &lt;= n; j++) { \t\t\t\tsum += a[i][j] * x[alpha[j]]; \t\t\t} \t\t\tx[alpha[i] - 1] = (b[i] - sum) \/ a[i][i]; \t\t\t \t\t}  \t\t\/\/ output \t\tPrintWriter pw = new PrintWriter(&quot;output.txt&quot;); \t\tfor (int i = 0; i &lt; n; i++) { \t\t\tpw.printf(Locale.US, &quot;x%d = %.5f \\n&quot;, i + 1, x[i]); \t\t}  \t\tpw.flush(); \t\tpw.close();  \t} } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u0413\u0430\u0443\u0441\u0441?<\/h3>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0421\u041b\u0410\u0423. \u041e\u0434\u0438\u043d \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u2014 \u043c\u0435\u0442\u043e\u0434 \u041a\u0440\u0430\u043c\u0435\u0440\u0430. \u041e\u043d \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u041f\u0440\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p><math>$$display$$ \\Delta = \\begin{vmatrix} a_{11} &#038; a_{12} &#038; a_{13}\\\\ a_{21} &#038; a_{22} &#038; a_{23} \\\\ a_{31} &#038; a_{32} &#038; a_{33}\\\\ \\end{vmatrix}, \\Delta_1 = \\begin{vmatrix} b_1 &#038; a_{12} &#038; a_{13}\\\\ b_2 &#038; a_{22} &#038; a_{23} \\\\ b_3 &#038; a_{32} &#038; a_{33}\\\\ \\end{vmatrix}, $$display$$<\/math><\/p>\n<p>  <\/p>\n<p><math>$$display$$ \\Delta_2 = \\begin{vmatrix} a_{11} &#038; b_1 &#038; a_{13}\\\\ a_{21} &#038; b_2 &#038; a_{23} \\\\ a_{31} &#038; b_3 &#038; a_{33}\\\\ \\end{vmatrix}, \\Delta_3 = \\begin{vmatrix} a_{11} &#038; a_{12} &#038; b_1\\\\ a_{21} &#038; a_{22} &#038; b_2 \\\\ a_{31} &#038; a_{32} &#038; b_3\\\\ \\end{vmatrix}, $$display$$<\/math><\/p>\n<p>  <\/p>\n<p><math>$$display$$ x_i = \\dfrac{\\Delta_i}{\\Delta}.$$display$$<\/math><\/p>\n<p>  \u041d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u2014 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c? <\/p>\n<p>  \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b <math>$inline$A = (a_{ij})$inline$<\/math> \u0435\u0441\u0442\u044c \u0441\u0443\u043c\u043c\u0430 <\/p>\n<p><math>$$display$$ \\sum\\limits_{1\\leq i_1 &lt; \\dots &lt; i_n \\leq n} (-1)^{N(i_1, \\dots, i_n)} a_{1i_1}\\dots a_{ni_n}, $$display$$<\/math><\/p>\n<p> \u0433\u0434\u0435 <math>$inline$N(i_1,\\dots, i_n)$inline$<\/math> \u2014 \u0437\u043d\u0430\u043a \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 <math>$inline$i_1, \\dots, i_n.$inline$<\/math><\/p>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <math>$inline$n!$inline$<\/math> \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c <math>$inline$n+1$inline$<\/math> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439. \u041f\u0440\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u0445 <math>$inline$n$inline$<\/math> \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 <math>$inline$n = 12$inline$<\/math> \u0447\u0438\u0441\u043b\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f <math>$inline$12!(12+1) = 6227020800,$inline$<\/math> \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 \u0413\u0430\u0443\u0441\u0441\u0430 \u0441 \u0430\u0441\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u043a\u043e\u0439 <math>$inline$n^3$inline$<\/math> \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c <math>$inline$12^3 = 1728$inline$<\/math> \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. <\/p>\n<h3>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/h3>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0421\u041b\u0410\u0423 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0438 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. \u041e\u043d\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0438 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0439 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u043e\u0442\u0432\u0435\u0442\u0443. <\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 <math>$inline$x^0$inline$<\/math> \u2014 \u044d\u0442\u043e \u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0435. \u041f\u043e \u043d\u0435\u043c\u0443 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440 <math>$inline$x^1$inline$<\/math> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0435. \u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 <math>$inline$||x^k &#8212; x^{k+1}|| &lt; \\varepsilon$inline$<\/math>, \u0433\u0434\u0435 <math>$inline$\\varepsilon$inline$<\/math> \u2014 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u043f\u0435\u0440\u0435\u0434 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u00ab\u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435\u00bb \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0447\u0442\u0438 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c. <\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u042f\u043a\u043e\u0431\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0421\u041b\u0410\u0423. <\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435:   <\/p>\n<p><math>$$display$$ \\sum\\limits_{j\\leq n} a_{ij}x_j = b_i, \\ i = \\overline{1,n}. $$display$$<\/math><\/p>\n<p>  \u041e\u0442\u0434\u0435\u043b\u0438\u043c <math>$inline$i$inline$<\/math>-\u043e\u0435 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u043c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435:   <\/p>\n<p><math>$$display$$ x_i = \\dfrac{b_i &#8212; \\sum\\limits_{j\\neq i} a_{ij}x_j}{a_{ii}}, \\ i = \\overline{1,n}.$$display$$<\/math><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0432\u0435\u0441\u0438\u043c \u00ab\u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0438\u00bb \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u042f\u043a\u043e\u0431\u0438:   <\/p>\n<p><math>$$display$$ x_i^k = \\dfrac{b_i &#8212; \\sum\\limits_{j\\neq i} a_{ij}x_j^k}{a_{ii}}, \\ i = \\overline{1,n},\\ k = 0,1,\\dots.$$display$$<\/math><\/p>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043d\u0443\u043b\u0435\u0439 \u043f\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u042f\u043a\u043e\u0431\u0438 \u043d\u0430 Java:<br \/>  <i>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <math>$inline$\\varepsilon$inline$<\/math> \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u044d\u043f\u0441\u0438\u043b\u043e\u043d.<\/i><\/p>\n<pre><code class=\"java\">import java.io.FileNotFoundException; import java.io.FileReader; import java.io.PrintWriter; import java.util.Locale; import java.util.Scanner;  public class JacobiMethod {  \tpublic static void main(String[] args) throws FileNotFoundException {  \t\tScanner sc = new Scanner(new FileReader(&quot;input.txt&quot;)); \t\tsc.useLocale(Locale.US);  \t\tint n = sc.nextInt();  \t\tdouble[][] a = new double[n + 1][n + 1]; \t\tdouble[] b = new double[n + 1]; \t\tdouble[] x0 = new double[n + 1];  \t\tfor (int i = 1; i &lt;= n; i++) { \t\t\tfor (int j = 1; j &lt;= n; j++) { \t\t\t\ta[i][j] = sc.nextDouble(); \t\t\t} \t\t\tb[i] = sc.nextDouble(); \t\t\tx0[i] = b[i] \/ a[i][i]; \t\t} \t\t\t\t \t\tdouble EPS = EPSCalc(); \t\tdouble[] x = new double[n+1]; \t\tdouble norm = Double.MAX_VALUE; \t\tint counter = 0; \t\tdo{ \t\t\tfor(int i = 1; i &lt;= n; i++) { \t\t\t\tdouble sum = 0; \t\t\t\tfor(int j = 1; j &lt;= n; j++) { \t\t\t\t\tif(j == i) continue; \t\t\t\t\tsum += a[i][j] * x0[j]; \t\t\t\t} \t\t\t\tx[i] = (b[i] - sum) \/ a[i][i]; \t\t\t} \t\t\tnorm = normCalc(x0, x, n); \t\t\tfor(int i = 1; i &lt;= n; i++) { \t\t\t\tx0[i] = x[i]; \t\t\t} \t\t\tcounter++; \t\t} while(norm &gt; EPS); \t\t \t\tPrintWriter pw = new PrintWriter(&quot;output.txt&quot;); \t\tpw.println(counter + &quot; iterations&quot;); \t\tfor (int i = 1; i &lt;= n; i++) { \t\t\tpw.printf(Locale.US, &quot;x%d = %f\\n&quot;, i, x0[i]); \t\t} \t\tpw.flush(); \t\tpw.close();  \t} \t \tstatic double normCalc(double []x1, double[] x2, int n) { \t\tdouble sum = 0; \t\tfor(int i = 1; i &lt;= n; i++) { \t\t\tsum += Math.abs(x1[i] - x2[i]); \t\t} \t\treturn sum; \t} \t \tstatic double EPSCalc () { \t\tdouble eps = 1;         while (1 + eps &gt; 1) {             eps \/= 2;         }         return eps; \t}  } <\/code><\/pre>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043c\u0435\u0442\u043e\u0434\u0430 \u042f\u043a\u043e\u0431\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043b\u0430\u043a\u0441\u0430\u0446\u0438\u0438. \u0415\u0433\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f. \u041e\u043f\u0438\u0448\u0435\u043c \u0432 \u043a\u0440\u0430\u0442\u0446\u0435 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0438\u0434\u0435\u044e \u043c\u0435\u0442\u043e\u0434\u0430. <\/p>\n<p>  \u0418\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0440\u0430\u0437\u0438\u043c <math>$inline$x$inline$<\/math>, \u043d\u043e \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0438 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <math>$inline$\\omega$inline$<\/math>:   <\/p>\n<p><math>$$display$$ x_i^k = \\dfrac{\\omega\\left(b_i &#8212; \\sum\\limits_{j = 1}^{i-1}a_{ij}x_j^{k+1} &#8212; \\sum\\limits_{j = i+1}^n a_{ij}x_j^k\\right)}{a_{ii}} + (1-\\omega)x_i^k, \\ i = \\overline{1,n},\\ k = 0,1,\\dots.$$display$$<\/math><\/p>\n<p>  \u041f\u0440\u0438 <math>$inline$\\omega=1$inline$<\/math> \u044d\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 \u042f\u043a\u043e\u0431\u0438.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u00ab\u0445\u043e\u0440\u043e\u0448\u0435\u0435\u00bb <math>$inline$\\omega$inline$<\/math>. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043a\u0430\u043a\u043e\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0438\u0441\u043b\u043e <math>$inline$s$inline$<\/math> \u0438 \u0431\u0443\u0434\u0435\u043c \u0431\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <math>$inline$\\omega \\in (0,2)$inline$<\/math>, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u044b <math>$inline$||x^{k+1}-x^k||, \\ k = \\overline{1,s}$inline$<\/math>. \u0414\u043b\u044f \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043d\u043e\u0440\u043c \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u0434\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <math>$inline$\\omega$inline$<\/math>, \u0438 \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0443\u0434\u0435\u043c \u0440\u0435\u0448\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443. <\/p>\n<p>  \u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Java: <br \/>  <i>\u0437\u0434\u0435\u0441\u044c <math>$inline$s=5$inline$<\/math><\/i><\/p>\n<pre><code class=\"java\">import java.io.FileNotFoundException; import java.io.FileReader; import java.io.PrintWriter; import java.util.Locale; import java.util.Scanner;  public class SuccessiveOverRelaxation { \t \tpublic static void main(String[] args) throws FileNotFoundException { \t\t \t\tScanner sc = new Scanner(new FileReader(&quot;input.txt&quot;)); \t\tsc.useLocale(Locale.US);  \t\tint n = sc.nextInt();  \t\tdouble[][] a = new double[n + 1][n + 1]; \t\tdouble[] b = new double[n + 1]; \t\t \t\tfor (int i = 1; i &lt;= n; i++) { \t\t\tfor (int j = 1; j &lt;= n; j++) { \t\t\t\ta[i][j] = sc.nextDouble(); \t\t\t} \t\t\tb[i] = sc.nextDouble(); \t\t} \t\t \t\tdouble EPS = EPSCalc(); \t\t \t\tdouble w = bestRelaxationParameterCalc(a, b, n); \t\t         double[] x = new double[n + 1];                  int counter = 0;         double maxChange = Double.MAX_VALUE;         do {         \tmaxChange = 0;             for (int i = 1; i &lt;= n; i++) {                  double firstSum = 0;                 for (int j = 1; j &lt;= i - 1; j++) {                     firstSum += a[i][j] * x[j];                 }                  double secondSum = 0;                 for (int j = i + 1; j &lt;= n; j++) {                     secondSum += a[i][j] * x[j];                 }                  double lastTerm = (1 - w) * x[i];                 double z = (b[i] - firstSum - secondSum);                 double temp = (w * z) \/ a[i][i] + lastTerm ;                 maxChange = Math.max(maxChange, Math.abs(x[i] - temp));                 x[i] = temp;             }             counter++;         } while(maxChange &gt; EPS);                  PrintWriter pw = new PrintWriter(&quot;output.txt&quot;);         pw.println(w + &quot; is the best relaxation parameter&quot;); \t\tpw.println(counter + &quot; iterations&quot;); \t\tfor (int i = 1; i &lt;= n; i++) { \t\t\tpw.printf(Locale.US, &quot;x%d = %f\\n&quot;, i, x[i]); \t\t} \t\tpw.flush(); \t\tpw.close(); \t\t \t} \t \tstatic double bestRelaxationParameterCalc(double[][]a, double[]b, int n) { \t\t \tdouble bestW = 1, bestMaxChange = Double.MAX_VALUE;         for (double w = 0.05; w &lt;= 2; w += 0.05) {              double[] x = new double[n + 1];                          double maxChange = 0;             for (int s = 0; s &lt; 5; s++) {                 maxChange = 0;                 for (int i = 1; i &lt;= n; i++) {                      double firstSum = 0;                     for (int j = 1; j &lt;= i - 1; j++) {                         firstSum += a[i][j] * x[j];                     }                      double secondSum = 0;                     for (int j = i + 1; j &lt;= n; j++) {                         secondSum += a[i][j] * x[j];                     }                      double lastTerm = (1 - w) * x[i];                     double z = (b[i] - firstSum - secondSum);                     double temp = (w * z) \/ a[i][i] + lastTerm;                     maxChange = Math.max(maxChange, Math.abs(x[i] - temp));                     x[i] = temp;                 }             }              if (maxChange &lt; bestMaxChange) {                 bestMaxChange = maxChange;                 bestW = w;             }          }                  return bestW;          \t} \t \tstatic double EPSCalc () { \t\tdouble eps = 1;         while (1 + eps &gt; 1) {             eps \/= 2;         }         return eps; \t} \t } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0449\u0435 \u043c\u0430\u0441\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0421\u041b\u0410\u0423. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u0435\u0442\u043e\u0434 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043d\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043a\u043e\u043c\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0435 \u00ab\u043f\u0440\u043e\u0441\u0442\u044b\u0445\u00bb \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u0430\u043c; \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0433\u043e\u043d\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0430\u043a \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0440\u0435\u0445\u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0442\u0440\u0438\u0446. \u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u0430\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/418241\/\"> https:\/\/habr.com\/post\/418241\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/418241\/\" class=\"post__text post__text-html js-mediator-article\">\u0427\u0442\u043e \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0441\u044f\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441 \u0442\u0440\u0435\u043c\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438? \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0430\u043b\u0433\u0435\u0431\u0440\u0430\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439. \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u0443 \u0413\u0430\u0443\u0441\u0441\u0430?   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-288059","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288059"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288059\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}