Advertisement
Jade39

А11

May 4th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 19.69 KB | None | 0 0
  1. program NNNNN2;
  2.  
  3. {$APPTYPE CONSOLE}
  4. {$MAXSTACKSIZE 200000000}
  5. {$Q+,I+,R+}
  6.  
  7. uses
  8.   SysUtils;
  9.  
  10. CONST
  11.     eps=0.0001;
  12.     pi=3.1415926535897932384626433832795;
  13.  
  14. TYPE
  15.     vect=Array[1..1200] of Real;
  16.     t_vect=Array[1..1200] of vect;
  17.  
  18. VAR iter,iter1,i,j,n,m,i1,j1,n1,m1,k,kk,k1,sh1,sh2,ll : Integer;
  19.     norma,norma1,tau,ro,ro_, first,opt,opt1,ss,tt,ro1,ro_1 : Real;
  20.     r,f,y,p,w,tmp,pr1,pr2,pr3,y1,y2,y3 : T_VECT;
  21.     rr,zz,y12,y11,a33p,am,x,yy,pp,yy1,pq,xx,y4,q:vect;
  22.         T1,T2,Fr:Int64;
  23.     Code_time:Double;
  24. {-------------------------------------------------------------------------------}
  25. function RDTSC: Int64; register; //????????? ?????????? ?????? ??????????, ?? ??????? ??? ?????????
  26.  asm
  27.    rdtsc
  28.  end;
  29. FUNCTION scalar(v1,v2: T_VECT;n,m:integer): Real;
  30. Var res : Real;
  31.     i,j : Integer;
  32. Begin
  33.  res:=0;
  34.  For i:=1 To n Do
  35.      For j:=1 To m Do
  36.          res:=res + v1[i][j]*v2[i][j];
  37.  scalar:=res;
  38. End;
  39. {-------------------------------------------------------------------------------}
  40. procedure print(a:t_vect;n,m:integer);
  41. var i,j:integer;
  42. begin
  43.     for i:=1 to n do begin
  44.     for j:=1 to m do begin
  45.       write(a[i,j]:6:4,' ');end;writeln;end;
  46. end;
  47. {-------------------------------------------------------------------------------}
  48. FUNCTION scalar1(v1,v2: vect;n:integer): Real;
  49. Var res : Real;
  50.     i,j : Integer;
  51. Begin
  52.  res:=0;
  53.  For i:=1 To n Do
  54.          res:=res + v1[i]*v2[i];
  55.  scalar1:=res;
  56. End;
  57. {-------------------------------------------------------------------------------}
  58.  function minus(a,b:vect;m:integer):vect;
  59. var i,j,k:integer;
  60. tmp:real;
  61. c:vect;
  62. begin
  63. FillChar(c,sizeof(c),0);
  64. for i:=1 to m do
  65.      c[i]:=a[i]-b[i];
  66.   minus:=c;
  67. end;
  68. {-------------------------------------------------------------------------------}
  69.  function plus(a,b:vect;m:integer):vect;
  70. var i,j,k:integer;
  71. tmp:real;
  72. c:vect;
  73. begin
  74. for i:=1 to m do
  75.      c[i]:=a[i]+b[i];
  76.   plus:=c;
  77. end;
  78. {-------------------------------------------------------------------------------}
  79. function pulti(a:T_VECT;b:vect;m:integer):vect;
  80. var i,j,k:integer;
  81. tmp:real;
  82. c:vect;
  83. begin
  84.  
  85.   for i:=1 to m do begin
  86.      tmp:=0;
  87.      for k:=1 to m do begin
  88.          tmp:=tmp+a[i][k]*b[k];
  89.      end;
  90.      c[i]:=tmp;
  91.    end;
  92.    pulti:=c;
  93. end;
  94. {-------------------------------------------------------------------------------}
  95. function pulti1(a:real;b:vect;m:integer):vect;
  96. var i,j,k:integer;
  97. c:vect;
  98. begin
  99. FillChar(c,sizeof(c),0);
  100.   for i:=1 to m do begin
  101.          c[i]:=a*b[i];
  102.      end;
  103.    pulti1:=c;
  104. end;
  105. {-------------------------------------------------------------------------------}
  106. FUNCTION raz_raz1 (r: T_VECT;n,m:integer): T_VECT;
  107. Var res,z : T_VECT;
  108.     i,j : Integer;
  109. Begin
  110.  FillChar(res,sizeof(res),0);
  111.  
  112.     For i:=1 To n  Do Begin
  113.                RES[i,1]:=2*R[i,1];
  114.                If i<>1 Then
  115.                     RES[i,1]:=RES[i,1]- 0.5*R[i-1,1];
  116.          If i<>n Then
  117.                     RES[i,1]:=RES[i][1] -  0.5*R[i+1,1];
  118.  
  119.                     RES[i,1]:=RES[i][1] - R[i,2];
  120.          End;
  121.         // print(res,n,m);
  122.           //z:=res;
  123. For i:=1 To n  Do Begin
  124.          For j:=2 To m Do Begin
  125.  
  126.                RES[i,j]:=4*r[i,j];
  127.                If i<>1 Then
  128.                     RES[i,j]:=RES[i,j]- r[i-1,j];
  129.          If i<>n Then
  130.                     RES[i,j]:=RES[i][j] -  r[i+1,j];
  131.                If j<>1 Then
  132.                     RES[i,j]:=RES[i][j] - r[i,j-1];
  133.                If j<>m Then
  134.                     RES[i,j]:=RES[i][j] - r[i,j+1];
  135.      End;
  136.  End;
  137.  
  138.  raz_raz1:=RES;
  139. End;
  140. {-------------------------------------------------------------------------------}
  141. FUNCTION GET_TAU1(r: real; p: T_VECT; n,m:integer): Real;
  142. Var s2 : Real;
  143.     tmp : T_VECT;
  144.     i,j : Integer;
  145. Begin
  146.  s2:=0;
  147.  FillChar(tmp,sizeof(tmp),0);
  148.  tmp:=raz_raz1(p,n,m);
  149.  For i:=1 To n  Do
  150.          For j:=1 To m Do
  151.                s2:=s2 + TMP[i,j]*P[i,j];
  152.  GET_TAU1:=r/s2;
  153. End;
  154. {-------------------------------------------------------------------------------}
  155. FUNCTION SSOR_PRE1(f: T_VECT;n,m:integer): T_VECT;
  156. Var y,tmp,r,y2 : T_VECT;
  157.     iter,i,j : Integer;
  158.     norma,prev,s,w : Real;
  159. Begin
  160.  iter:=0;
  161.  norma:=0;
  162.  prev:=0;
  163.  s:=0;
  164.  
  165.  w:=2/(1+sin(pi/(m+1)));
  166.  
  167.  FillChar(y,sizeof(y),0);
  168.  FillChar(r,sizeof(r),0);
  169.  FillChar(tmp,sizeof(tmp),0);
  170.  tmp:=raz_raz1(y,n,m);
  171.  For i:=1 To N Do
  172.          For j:=1 To M Do Begin
  173.                R[i,j]:=F[i,j] - TMP[i,j];
  174.          If norma<abs(R[i,j]) Then
  175.             norma:=abs(R[i,j]);
  176.          End;
  177.  
  178.  For i:=1 To N Do begin
  179.          s:=0;
  180.              Y[i,1]:=(1-w)*Y[i,1];
  181.              If i<>1 Then
  182.                   s:=s + 0.5*Y[i-1,1];
  183.          If i<>n Then
  184.                   s:=s + 0.5*Y[i+1,1];
  185.                   s:=s + Y[i,2];
  186.              s:=s * 0.5*w;
  187.              Y[i,1]:=Y[i][1] + s + 0.5*w*F[i,1];
  188.          //u(i,j) = (1-w)*u(i,j)+0.25*w*(u(i-1,j)+u(i,j-1)+u(i+1,j)+u(i,j+1))+0.25*w*f(i,j);
  189.      End;
  190.  
  191.      For i:=1 To N Do begin
  192.      For j:=2 To M Do Begin
  193.          s:=0;
  194.          //if j<>1 then
  195.              Y[i,j]:=(1-w)*Y[i,j];
  196.              If i<>1 Then
  197.                   s:=s + Y[i-1,j];
  198.          If i<>n Then
  199.                   s:=s + Y[i+1,j];
  200.          If j<>1 Then
  201.                   s:=s + Y[i,j-1];
  202.          If j<>m Then
  203.                   s:=s + Y[i,j+1];
  204.              s:=s * 0.25*w;
  205.         // if j<>1 then
  206.              Y[i,j]:=Y[i][j] + s + 0.25*w*F[i,j];
  207.          //u(i,j) = (1-w)*u(i,j)+0.25*w*(u(i-1,j)+u(i,j-1)+u(i+1,j)+u(i,j+1))+0.25*w*f(i,j);
  208.      End;
  209.      end;
  210.  
  211.  //obratnii hod
  212.  For i:=n DownTo 1 Do
  213.          For j:=m DownTo 2 Do Begin
  214.                s:=0;
  215.          //if j<>1 then
  216.                Y[i,j]:=(1-w)*Y[i,j];
  217.                If i<>1 Then
  218.                     s:=s + Y[i-1,j];
  219.                If i<>n Then
  220.                     s:=s + Y[i+1,j];
  221.                If j<>1 Then
  222.                     s:=s + Y[i,j-1];
  223.                If j<>m Then
  224.                     s:=s + Y[i,j+1];
  225.          s:=s * 0.25*w;
  226.          //if j<>1 then
  227.          Y[i,j]:=Y[i][j] + s + 0.25*w*F[i,j];
  228.                //u(i,j) = (1-w)*u(i,j)+0.25*w*(u(i-1,j)+u(i,j-1)+u(i+1,j)+u(i,j+1))+0.25*w*f(i,j);
  229.          End;
  230.  
  231.         For i:=n DownTo 1 Do begin
  232.                s:=0;
  233.                Y[i,1]:=(1-w)*Y[i,1];
  234.                If i<>1 Then
  235.                     s:=s + 0.5*Y[i-1,1];
  236.                If i<>n Then
  237.                     s:=s + 0.5*Y[i+1,1];
  238.                     s:=s + Y[i,2];
  239.          s:=s * 0.5*w;
  240.          Y[i,1]:=Y[i][1] + s + 0.5*w*F[i,1];
  241.                //u(i,j) = (1-w)*u(i,j)+0.25*w*(u(i-1,j)+u(i,j-1)+u(i+1,j)+u(i,j+1))+0.25*w*f(i,j);
  242.          End;
  243.  
  244.  
  245.     //norma neviazki
  246.  For i:=1 To n Do
  247.         For j:=1 To m Do Begin
  248.             If i<>1 Then
  249.                  norma:=norma + Y[i-1,j];
  250.             If i<>n Then
  251.                  norma:=norma + Y[i+1,j];
  252.             If j<>1 Then
  253.                  norma:=norma + Y[i,j-1];
  254.             If j<>m Then
  255.                  norma:=norma + Y[i,j+1];
  256.             norma:=norma - 4*Y[i,j];
  257.             norma:=abs(F[i,j] + norma);
  258.         End;
  259.  
  260.     SSOR_PRE1:=Y;
  261. End;
  262. {-------------------------------------------------------------------------------}
  263. FUNCTION raz_raz (r: T_VECT;n,m:integer): T_VECT;
  264. Var res : T_VECT;
  265.     i,j : Integer;
  266. Begin
  267.  //FillChar(res,sizeof(res),0);
  268.  For i:=1 To n  Do Begin
  269.          For j:=1 To m Do Begin
  270.                RES[i,j]:=4*R[i,j];
  271.                If i<>1 Then
  272.                     RES[i,j]:=RES[i,j] - R[i-1,j];
  273.          If i<>n Then
  274.                     RES[i,j]:=RES[i][j] -  R[i+1,j];
  275.                If j<>1 Then
  276.                     RES[i,j]:=RES[i][j] - R[i,j-1];
  277.                If j<>m Then
  278.                     RES[i,j]:=RES[i][j] - R[i,j+1];
  279.      End;
  280.  End;
  281.  
  282.  raz_raz:=RES;
  283. End;
  284. {-------------------------------------------------------------------------------}
  285. FUNCTION GET_TAU(r: real; p: T_VECT; n,m:integer): Real;
  286. Var s2 : Real;
  287.     tmp : T_VECT;
  288.     i,j : Integer;
  289. Begin
  290.  s2:=0;
  291.  FillChar(tmp,sizeof(tmp),0);
  292.  tmp:=raz_raz(p,n,m);
  293.  For i:=1 To n  Do
  294.          For j:=1 To m Do
  295.                s2:=s2 + TMP[i,j]*P[i,j];
  296.  GET_TAU:=r/s2;
  297. End;
  298. {-------------------------------------------------------------------------------}
  299. FUNCTION SSOR_PRE(f: T_VECT;n,m:integer): T_VECT;
  300. Var y,tmp,r : T_VECT;
  301.     iter,i,j : Integer;
  302.     norma,prev,s,w : Real;
  303. Begin
  304.  iter:=0;
  305.  norma:=0;
  306.  prev:=0;
  307.  s:=0;
  308.  w:=2/(1+sin(pi/(M+1)));
  309.  //writeln('w= ',w:4:4);
  310.  
  311.  FillChar(y,sizeof(y),0);
  312.  FillChar(r,sizeof(r),0);
  313.  FillChar(tmp,sizeof(tmp),0);
  314.  tmp:=raz_raz(y,n,m);
  315.  For i:=1 To N Do
  316.          For j:=1 To M Do Begin
  317.                R[i,j]:=F[i,j] - TMP[i,j];
  318.          If norma<abs(R[i,j]) Then
  319.             norma:=abs(R[i,j]);
  320.          End;
  321.  For i:=1 To N Do
  322.      For j:=1 To M Do Begin
  323.          s:=0;
  324.              Y[i,j]:=(1-w)*Y[i,j];
  325.              If i<>1 Then
  326.                   s:=s + Y[i-1,j];
  327.          If i<>n Then
  328.                   s:=s + Y[i+1,j];
  329.          If j<>1 Then
  330.                   s:=s + Y[i,j-1];
  331.          If j<>m Then
  332.                   s:=s + Y[i,j+1];
  333.              s:=s * 0.25*w;
  334.              Y[i,j]:=Y[i][j] + s + 0.25*w*F[i,j];
  335.          //u(i,j) = (1-w)*u(i,j)+0.25*w*(u(i-1,j)+u(i,j-1)+u(i+1,j)+u(i,j+1))+0.25*w*f(i,j);
  336.      End;
  337.  //obratnii hod
  338.  For i:=n DownTo 1 Do
  339.          For j:=n DownTo 1 Do Begin
  340.                s:=0;
  341.                Y[i,j]:=(1-w)*Y[i,j];
  342.                If i<>1 Then
  343.                     s:=s + Y[i-1,j];
  344.                If i<>n Then
  345.                     s:=s + Y[i+1,j];
  346.                If j<>1 Then
  347.                     s:=s + Y[i,j-1];
  348.                If j<>m Then
  349.                     s:=s + Y[i,j+1];
  350.          s:=s * 0.25*w;
  351.          Y[i,j]:=Y[i][j] + s + 0.25*w*F[i,j];
  352.                //u(i,j) = (1-w)*u(i,j)+0.25*w*(u(i-1,j)+u(i,j-1)+u(i+1,j)+u(i,j+1))+0.25*w*f(i,j);
  353.          End;
  354.  
  355.     //norma neviazki
  356.  For i:=1 To n Do
  357.         For j:=1 To m Do Begin
  358.             If i<>1 Then
  359.                  norma:=norma + Y[i-1,j];
  360.             If i<>n Then
  361.                  norma:=norma + Y[i+1,j];
  362.             If j<>1 Then
  363.                  norma:=norma + Y[i,j-1];
  364.             If j<>m Then
  365.                  norma:=norma + Y[i,j+1];
  366.             norma:=norma - 4*Y[i,j];
  367.             norma:=abs(F[i,j] + norma);
  368.         End;
  369.  
  370.     SSOR_PRE:=Y;
  371. End;
  372. {-------------------------------------------------------------------------------}
  373. function A33(a,b:integer):T_VECT;
  374. var
  375. i,j:integer;
  376. q:T_VECT;
  377. begin
  378. for i:=1 to a do  begin
  379. for j:=1 to b do  begin
  380.        if i=j then q[i,j]:=4
  381.        else if (i+1=j) or (i=j+1) then q[i,j]:=-1
  382.        else   q[i,j]:=0;
  383.    end;end;
  384.  
  385.      A33:=q;
  386. end;
  387. {-------------------------------------------------------------------------------}
  388. procedure Grad0(n,m:integer;r:T_VECT);
  389.  
  390. BEGIN
  391.  
  392.  FillChar(y,sizeof(y),0);
  393.  FillChar(p,sizeof(p),0);
  394.  FillChar(w,sizeof(w),0);
  395.  FillChar(tmp,sizeof(tmp),0);
  396.  iter:=0;
  397.  //norma:=eps+1;
  398.  tau:=0;
  399.  ro:=0;
  400.  ro_:=0;
  401.  
  402.  
  403.  p:=ssor_pre1(r,n,m);
  404.  ro:=scalar(p,r,n,m);
  405.  
  406.  While true Do Begin
  407.      INC(iter);
  408.         {
  409.      Writeln('---------------------------------------------');
  410.      writeln(iter,' ');
  411.           }
  412.          norma:=0;
  413.          tau:=get_tau1(ro,p,n,m);
  414.     // writeln('--------------opt---------------');
  415.     //writeln('opt= ',tau);
  416.          For i:=1 To n Do
  417.                For j:=1 To m Do
  418.                      Y[i,j]:=Y[i][j] + tau*P[i,j];
  419.             // writeln('--------------x---------------');
  420.             // print(y,n,m);
  421.      tmp:=raz_raz1(p,n,m);
  422.          For i:=1 To n Do
  423.          For j:=1 To m Do Begin
  424.                      r[i,j]:=r[i][j] - tau*TMP[i,j];
  425.                norma:=norma+abs(r[i,j]);
  426.                End;
  427.         // writeln('--------------r---------------');
  428.         // print(r,n,m);
  429.  
  430.      w:=ssor_pre1(r,n,m); //pereschet po formyle
  431.      //writeln('w= ',w[1,1]);
  432.  
  433.          ro_:=ro;
  434.          ro:=scalar(w,r,n,m);
  435.  
  436.          For i:=1 To n Do
  437.          For j:=1 To m Do
  438.              P[i,j]:=W[i,j] + (ro/ro_)*P[i,j];
  439.             // writeln('--------------p---------------');
  440.             //print(p,n,m);
  441.  
  442.                if iter=1 then first:=norma;
  443.     //writeln('norma_next=',norma:6:3,' norma1=',first:6:3, ' ');
  444.      if (abs(norma/first)<eps)then break;
  445.  
  446.  End;
  447.  
  448. for i:=1 to n do begin
  449.   for j:=1 to m do
  450.     if j=1 then
  451.       y4[i]:=y[i,j];
  452. end;
  453.   //Writeln('--------------D-N iter=',iter,' ');
  454.  
  455. end;
  456. {-------------------------------------------------------------------------------}
  457. procedure Grad(n,m:integer;r:T_VECT);
  458.  
  459. BEGIN
  460.  
  461.  
  462.  FillChar(y,sizeof(y),0);
  463.  FillChar(p,sizeof(p),0);
  464.  FillChar(w,sizeof(w),0);
  465.  FillChar(tmp,sizeof(tmp),0);
  466.  iter:=0;
  467.  norma:=eps+1;
  468.  tau:=0;
  469.  ro:=0;
  470.  ro_:=0;
  471.  
  472.  
  473.  p:=ssor_pre(r,n,m);
  474.  
  475.  ro:=scalar(p,r,n,m);
  476.  
  477.  While true Do Begin
  478.      INC(iter);
  479.  
  480.          norma:=0;
  481.          tau:=get_tau(ro,p,n,m);
  482.      //writeln('tau= ',tau);
  483.          For i:=1 To n Do
  484.                For j:=1 To m Do
  485.                      Y[i,j]:=Y[i][j] + tau*P[i,j];
  486.      tmp:=raz_raz(p,n,m);
  487.          For i:=1 To n Do
  488.          For j:=1 To m Do Begin
  489.                      r[i,j]:=r[i][j] - tau*TMP[i,j];
  490.                norma:=norma+abs(r[i,j]);
  491.                End;
  492.  
  493.      if iter=1 then first:=norma;
  494.      if norma/first<eps then break;
  495.      w:=ssor_pre(r,n,m); //pereschet po formyle
  496.      //writeln('w= ',w[1,1]);
  497.          ro_:=ro;
  498.          ro:=scalar(w,r,n,m);
  499.  
  500.          For i:=1 To n Do
  501.          For j:=1 To m Do
  502.              P[i,j]:=W[i,j] + (ro/ro_)*P[i,j];
  503.  End;
  504.  //writeln('kol-vo dirixle iter=',iter);
  505. end;
  506. {-------------------------------------------------------------------------------}
  507. //òóò íà ëèíèè ñöåïëåíèÿ
  508. procedure nev(n,k,bb,m:integer;z:T_VECT);
  509. var
  510. i,l,i1:integer;
  511. sh:T_VECT;
  512. begin
  513.    Grad(n,k,z);
  514.    sh:=y;
  515.    if(bb=1) then begin
  516.           l:=1;
  517.           for i:=m to n do begin
  518.           zz[l]:=sh[i,n];l:=l+1;//k:=k+1;
  519.           end; end   //end;//end;end;
  520.    else if (bb=2) then begin
  521.           l:=1;
  522.           for i1:=1 to n do begin
  523.             zz[l]:=sh[i1,1];l:=l+1;
  524.           end;end
  525.    else write('ne pravilno vveli bb');
  526. end;
  527. {-------------------------------------------------------------------------------}
  528. //òóò íàõîäèì am
  529. procedure naxod_am(k,n,n1,m,m1:integer;rr,pq:vect);
  530. var
  531. i,j,i1,j1,ll:integer;
  532. begin
  533.               ll:=k;
  534.              for i:=1 to n do begin
  535.  
  536.              for j:=1 to m do begin
  537.               if(i=ll)and(j=m) then begin
  538.                pr1[i,j]:=pq[ll-k+1];
  539.                ll:=ll+1;
  540.               end
  541.              else pr1[i,j]:=0;
  542.              end;end;
  543.  
  544. nev(n,m,1,k,pr1);
  545. y11:=zz;
  546.  
  547.  sh2:=1;
  548.  
  549.           for i:=1 to n1 do begin
  550.           for j:=1 to m1 do begin
  551.             if (j=1) then begin
  552.               pr2[i,j]:=pq[sh2];
  553.               sh2:=sh2+1;
  554.             end
  555.             else pr2[i,j]:=0;end;end;
  556. nev(n1,m1,2,k,pr2);
  557. y12:=zz;
  558.   //for i1:=1 to n1 do
  559.   //writeln(y12[i1]:2:4,' ');
  560. //Writeln('------------------A33*p--------------------------');
  561. a33p:=pulti(A33(n1,m1),pq,n1);
  562. //for i:=1 to n1 do
  563.   //Writeln(a33p[i]:6:2,' ');
  564. //Writeln('------------------A33*p-2*p-3*p--------------------------');
  565. am:=minus(a33p,plus(y11,y12,n1),n1);
  566.   //for i:=1 to n1 do
  567.   //Writeln(am[i]:6:2,' '); Writeln;//am=sp
  568. //-----------------------------------------------------------------------
  569.  
  570. end;
  571. {-------------------------------------------------------------------------------}
  572. procedure Grad2(n,m,n1,m1,k:integer;rr:vect);
  573. var
  574. iter,d:integer;
  575. x:vect;
  576. begin
  577. iter:=0;
  578. norma1:=0;
  579.  FillChar(x,sizeof(x),0);
  580.  kk:=1;
  581.    // ïðàâà ÷àñòü ìàëîãî
  582. for j1:=1 to m1+1 do begin
  583. for i1:=1 to n1 do begin
  584.   if (j1=1) then begin
  585.    pr3[i1,j1]:=rr[kk];
  586.    kk:=kk+1;
  587.   end
  588.   else pr3[i1,j1]:=0;
  589. end;
  590. end;
  591.   d:=m1+1;
  592.  // writeln('do grad0');
  593. Grad0(n1,d,pr3);
  594.  //writeln('posle grad0');
  595.  pq:=y4;
  596.  ro1:=scalar1(pq,rr,n1);
  597.  {
  598.  writeln('-------p_0----------');
  599.  for i:=1 to n1 do
  600.  writeln(pq[i]:6:4,' ');
  601.  writeln('-----------------');
  602.  writeln('ro= ',ro1:6:6,' ');
  603.                  }
  604.  
  605. //while iter>0 do begin
  606. While true Do Begin
  607.  
  608. //iter:=iter-1;
  609. inc(iter);
  610.            {
  611. writeln('---------------------------------------------------- ');
  612. writeln('íîìåð èòåðàöèè:',iter);
  613.            }
  614. naxod_am(k,n,n1,m,m1,rr,pq);
  615.           {
  616.   Writeln('------------------a_m--------------------------');
  617. for i:=1 to n1 do
  618. writeln(am[i]:6:5,' ');
  619. writeln('---------------------------------------------------- ');
  620.            }
  621. tt:=scalar1(am,pq,n1);
  622.  
  623. //writeln('ro=',ro1:6:10,' ');
  624. //writeln('scalar1(am,pq,n1)=',tt:6:2,' ');
  625.  
  626. opt:=ro1/tt;
  627.         {
  628.   writeln('lamda opt=',opt:6:10,' ');
  629.   Writeln('------------------x_m+1--------------------------');
  630.           }
  631.  yy1:=pulti1(opt,pq,n1);
  632.  
  633.  x:=plus(x,yy1,n1);
  634.       {
  635.  for i:=1 to n1 do
  636.  writeln(x[i]:6:10,' ');writeln;
  637.  
  638.  Writeln('------------------r_m+1--------------------------');
  639.     }
  640.  rr:=minus(rr,pulti1(opt,am,n1),n1);
  641.  
  642.    if iter=1 then begin
  643.     For i:=1 To N  Do
  644.        norma1:=norma1+abs(rr[i]);
  645.   end;
  646.        {
  647.  for i:=1 to n1 do
  648.  writeln(rr[i]:6:10,' ');writeln;
  649.     }
  650.  
  651.  
  652.   kk:=1;
  653.    // ïðàâà ÷àñòü ìàëîãî
  654. for j1:=1 to m1+1 do begin
  655. for i1:=1 to n1 do begin
  656.   if (j1=1) then begin
  657.    pr3[i1,j1]:=rr[kk];
  658.    kk:=kk+1;
  659.   end
  660.   else pr3[i1,j1]:=0;
  661. end;
  662. end;
  663.  
  664. Grad0(n1,d,pr3);
  665.  q:=y4;
  666.             {
  667.    writeln('-----------------Íîâàÿ ïîïðàâêà q_m+1--------------');
  668.    for i:=1 to n1 do
  669.    writeln(q[i]:6:10,' ');
  670.    }
  671.  ro_1:=ro1;
  672.  
  673. //writeln('---------------------------------------------------- ');
  674.  ro1:=scalar1(q,rr,n1);
  675.  //writeln('ro_m+1=',ro1:4:20,' ');
  676.  
  677.  opt1:=ro1/ro_1;
  678.  pq:=plus(q,pulti1(opt1,pq,n1),n1);
  679.           {
  680.  Writeln('------------------p_m+1--------------------------');
  681.  for i:=1 to n1 do
  682.   writeln(pq[i]:6:10,' ');
  683.             }
  684.  
  685.                  norma:=0;
  686.      For i:=1 To N  Do
  687.                      norma:=norma+abs(rr[i]);
  688.               ss:=abs(norma/norma1);
  689.                 {
  690.           writeln('----------óñëîâèå âûõîà:abs(norma/norma1)<eps--------------');
  691.           writeln(ss:6:10,' < ',eps:6:6);
  692.                      }
  693.          If (ss<eps)  Then
  694.                 break;
  695.  
  696. end;
  697. xx:=x;
  698. iter1:=iter;
  699.  writeln('----------óñëîâèå âûõîà:abs(norma/norma1)<eps--------------');
  700.           writeln(ss:6:10,' < ',eps:6:6);
  701.  
  702. end;
  703.  
  704. {-------------------------------------------------------------------------------}
  705. procedure Grad3(n,m,n1,m1:integer;pr1,pr2:T_vect);
  706. begin
  707. Grad(n,m,pr1);
  708. y1:=y;
  709. {
  710. WriteLn('----------------Ðåøåíèå 1 îáëàñòè------------- ');WriteLn;
  711.  For i:=1 To n Do Begin
  712.      For j:=1 To m Do
  713.          write(y1[i][j]:6:2,'  ');
  714.      WriteLn;
  715.  
  716.  End; }
  717.  
  718.  // WriteLn;
  719. Grad(n1,m1,pr2);
  720. y2:=y;
  721. {
  722. WriteLn('----------------Ðåøåíèå 2 îáëàñòè------------- ');WriteLn;
  723.  For i:=1 To n1 Do Begin
  724.      For j:=1 To m1 Do
  725.          write(y2[i][j]:6:2,'  ');
  726.      WriteLn;
  727.  
  728.  End;
  729.  }
  730.  //readln;
  731. end;
  732. {-------------------------------------------------------------------------------}
  733.  
  734. begin
  735. assign(output,'output.txt');
  736. rewrite(output);
  737. T1:=RDTSC;
  738. sleep(1000);
  739. T2:=RDTSC;
  740. Fr:=T2-T1;
  741.  
  742. T1:=RDTSC;
  743. n:=7; m:=7; // ðàçìåð áîëüøîãî îáëàñòè
  744. n1:=3; m1:=3; // ðàçìåð ìåíüøåãî
  745. k:=n-n1+1; k1:=k+n1-1;  // ê - ñ êàêîé ñòðîêè ...
  746. //k:=5;
  747.  
  748. for i:=1 to n do
  749. for j:=1 to m do
  750. pr1[i,j]:=16;
  751. //pr1[15,15]:=1;   // ïðàâàÿ ÷àñòü áîëüøîãî
  752.  
  753. for i1:=1 to n1 do
  754. for j1:=1 to m1 do
  755. pr2[i1,j1]:=16;
  756. //pr2[7,7]:=1;  // ïðàâà ÷àñòü ìàëîãî
  757.  
  758. Grad3(n,m,n1,m1,pr1,pr2);
  759.  
  760. //writeln('-------------íåâÿçêà íà ëèíèè ñöåïëåíèÿ------------');writeln;
  761.       for i:=1 to n1 do  begin
  762.         rr[i]:=y2[i][1]+y1[k+i-1][n]+16;
  763.        // writeln(rr[i]:6:6,' ');
  764.        end;
  765.  
  766. Grad2(n,m,n1,m1,k,rr);
  767.  
  768. // writeln('---------Íàø âåêòîð çà za stolko iter=', iter1,' èòåðàöèé--------------');
  769.    {
  770.  for i:=1 to n1 do
  771.     writeln(xx[i]:6:4,' '); writeln;
  772.  
  773.  
  774.               ll:=k;
  775.              for i:=1 to n do begin
  776.  
  777.              for j:=1 to n do begin
  778.               if(i=ll)and(j=n) then begin
  779.                pr1[i,j]:=xx[ll-k+1]+16;
  780.                ll:=ll+1;
  781.               end
  782.              else pr1[i,j]:=16;
  783.              end;end;
  784.  sh2:=1;
  785.           for i:=1 to n1 do begin
  786.           for j:=1 to n1 do begin
  787.             if (j=1) then begin
  788.               pr2[i,j]:=xx[sh2]+16;
  789.               sh2:=sh2+1;
  790.             end
  791.             else pr2[i,j]:=16;end;end;
  792.  
  793. Grad3(n,m,n1,m1,pr1,pr2); writeln;
  794.  
  795. writeln('-------------Ðåøåíèå çàäà÷è------------'); writeln;
  796.     for i:=1 to n do begin
  797.     for j:=1 to n+n1+1 do begin
  798.       if (j<=n) then
  799.       write(y1[i][j]:6:2,' ')
  800.       else if (i>=k)and(i<=k+n1-1) and(j=n+1) then
  801.       write(xx[i-k+1]:6:2,' ')
  802.       else if (i>=k)and(i<=k+n1-1)and (j>n+1)and(j<=n+n1+1) then
  803.       write(y2[i-k+1][j-n-1]:3:2,' ')
  804.       else write(' ')
  805.       end;writeln;end;
  806.                     }
  807.                          T2:=RDTSC;
  808. Code_Time:=((T2-T1)/Fr*1000)/1000;
  809. writeln('vrem1=',Code_Time:4:1,' mc');
  810. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement