< -->

{==================}Program Runge_Kutt_Diff_Ur;{======================}
     {Ðåøåíèå äèôôåðåíöèàëüíûõ óðàâíåíèé ìåòîäàìè Ðóíãå-Êóòòà}
     {Ëàáîðàòîðíàÿ ðàáîòà ïî âû÷èñëèòåëüíîé ôèçèêå (×ÌèÌÌ) ¹2}
(*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
 {[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]}
(*<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>*)
{                                 Íà÷. - 24 îêòÿáðÿ 2002ã.(÷ò)
   Îêðóãèí      Û²°   Àëåêñàíäð. Copiright 2002ã.(C) v3.1 (November, 19)
                 =
   ~~~~~~~      +++    ~~~~~~~       /-_-_-_-_-^^^-_-_!_-_-^^^-_-_-_-_-\
    ~~~~~      !!!!!    ~~~~~        |ÛÛÛÛÛÛÛÛÛÛÛ\ÛÛÛÛÛÛÛÛÛ/ÛÛÛÛÛÛÛÛÛÛÛ|
     ~~~      _______    ~~~         |Û/\²²²²²²²²²²\²²^²²/²²²²²²²²²²/\Û|
      ~      ---------    ~          |ÛÛ\\²²°°°°°°°°°\°/°°°°°°°°°²²//ÛÛ|
            ###########              |ÛÛÛ²\²°°°ÚÄÄÄÄÄÄ|ÄÄÄÄÄÄ¿°°°²/²ÛÛÛ|
    |||    ^^^^^^^^^^^^^    |||      |ÛÛÛ²²\°°°³ÉÍÍÍÍÍþÍÍÍÍÍ»³°°°/²²ÛÛÛ|
    |||   ÉÍÍÍÍÍÍÍÍÍÍÍÍÍ»   |||      |Û*Û²²²\°°³ºßß!ßßßßß!ßߺ³°°/²²²Û*Û|
    |||  |ºÚÄÄÄÄÄÄÄÄÄÄÄ¿º|  |||      |ÛÛÛ²²²°\°³ºÝÞÝÞÝÜÝÞÝÞݺ³°/°²²²ÛÛÛ|
        Þ|º³ÛÛÛÛÛÛÛÛÛÛÛ³º|Ý          |ÛÛÛ²²²°°\³ºÞÝÞÝÞßÞÝÞÝÞº³/°°²²²ÛÛÛ|
  ßßßß þÞ|º³Û²²²²²²²²²Û³º|Ýþ ÜÜÜÜ    |ÛÛ<>²<>°#-þßÜßÜßXßÜßÜßþ-#°<>²<>ÛÛ|
   <<< þÞ|º³Û²²°°°°°²²Û³º|Ýþ >>>     |ÛÛÛ²²²°°/³ºÞÝÞÝÞßÞÝÞÝÞº³\°°²²²ÛÛÛ|
  ßßßß þÞ|º³Û²²°°*°°²²Û³º|Ýþ ÜÜÜÜ    |ÛÛÛ²²²°/°³ºÝÞÝÞÝÜÝÞÝÞݺ³°\°²²²ÛÛÛ|
   >>> þÞ|º³Û²²°°°°°²²Û³º|Ýþ <<<     |Û*Û²²²/°°³ºÜ!ÜÜÜÜÜÜÜ!ܺ³°°\²²²Û*Û|
  ßßßß þÞ|º³Û²²²²²²²²²Û³º|Ýþ ÜÜÜÜ    |ÛÛÛ²²/°°°³ÈÍÍÍÍÍþÍÍÍÍͼ³°°°\²²ÛÛÛ|
        Þ|º³ÛÛÛÛÛÛÛÛÛÛÛ³º|Ý          |ÛÛÛ²/²°°°ÀÄÄÄÄÄÄ|ÄÄÄÄÄÄÙ°°°²\²ÛÛÛ|
   ///   |ºÀÄÄÄÄÄÄÄÄÄÄÄÙº|  \\\      |ÛÛ//²²°°°°°°°°°/°\°°°°°°°°°²²\\ÛÛ|
          ÈÍÍÍÍÍÍÍÍÍÍÍÍͼ            |Û\/²²²²²²²²²²/²²#²²\²²²²²²²²²²\/Û|
  /ÛÛÛÛÛÛÛÛÛßßßßßßßßßßßÛÛÛÛÛÛÛÛÛ\    |ÛÛÛÛÛÛÛÛÛÛÛ/ÛÛÛÛÛÛÛÛÛ\ÛÛÛÛÛÛÛÛÛÛÛ|
  \ÛÛÛÛÛÛÛÛÛÜÜÜÜÜÜÜÜÜÜÜÛÛÛÛÛÛÛÛÛ/    \-+-+-+-+-<<<-+-+=+-+->>>-+-+-+-+-/
}
{$E-}
{$N+}
{$D-}
{$G+}
Uses Graph, CRT;
type Float = Extended;
const
  t0  :  Float = 0.0  ;
  x0  :  Float = 10.0 ;
  b   :  Float = 6.0 ;
  h0  :  Float = 0.5 ;
  Sx  :  Float = 0.79 ; {maximum of function f1 is near 552.77328 }
  St  :  Float = 100.0 ; {Scale is 100 ed in 1 [max x = 600] }
                                 {0.79 : 79 in 100}
type
  PRslt = ^TRslt;
  TRslt = array [1..130] of String[80];
var
  Key : Char;
  Rslt : PRslt;
  N, NN : Longint;
  D, R, e : Integer;
  i : LongInt;
  x, t, h, C, C1, C2, C3, C4 : Float;
  delta, tt, Sn : Float;
  {   ^   }
  xk {x}, x1, k1, k2, k3, S, eps{epsilon} : Float;
  SSS : String;
  ff : Text;
{-=-=-=-=-=-=-=-=-=-=-=-=-}
Function f(t, x : Float) : Float;
begin
 f:= -2*(t-2.0)*x + sin(t)*exp(-t*t)*(t-2.0)*(t-2.0);
end;
{_+_+_+_+_+_+_+_+_+_+_+_+_+_+_}
Function f1(t : Float) : Float;
begin
 f1:= C*Exp(-Sqr(t-2))+Exp(-t*t)*(-(1/17)*t*t*(cos(t)+4*sin(t))+t*(C1*cos(t)+C2*sin(t))-C3*cos(t)-C4*sin(t));
end;
{_+_+_+_+_+_+_+_+_+_+_+_+_+_+_}
Procedure ViewData(tr, Anr, Rkr : Float);
begin
      Str(tr:5:5, SSS);
      OutTextXY(320, 10+NN*14, SSS);
      Str(Anr:5:5, SSS);
      OutTextXY(400, 10+NN*14, SSS);
      Str(RKr:5:5, SSS);
      OutTextXY(540, 10+NN*14, SSS)
end;
{-----------------------}
Procedure DataRead(k : Longint);
var
  j : Longint;
begin
  Reset(ff);
  for j := 1 to k-1 do
    if not EOF(ff) then ReadLn(ff, SSS);
  for j := 1 to 130 do
    if not EOF(ff) then ReadLn(ff, Rslt^[j]) else Rslt^[j]:=' ';
  Close(ff);
end;
{---------------}
Procedure ScreenData(k : Longint);
var
  j : Longint;
begin
  ClrScr;
  GotoXY(1,1);
  TextColor(Yellow);
  WriteLn('Ïåðåìåííàÿ t          Òî÷íîå çíà÷åíèå        Ïðèáëèçèòåëüíîå çíà÷åíèå');
  TextColor(LightGray);
  for j := k+1 to 23+k do
    WriteLn(Rslt^[j]);
  TextColor(LightMagenta);
  Write('N= ', N,'; i= ', i);
end;
{-----------------------}
Procedure DoScreen;
begin
  ClearViewPort;
  SetColor(DarkGray);
  MoveTo(0, 477);
  LineTo(640, 477);
  LineTo(630, 475);
  LineTo(630, 479);
  LineTo(640, 477);
  MoveTo(2, 480);
  LineTo(2, 0);
  LineTo(0, 10);
  LineTo(4, 10);
  LineTo(2, 0);
  SetColor(LightGray);
  for i := 0 to 6 do Line(i*100+2, 476, i*100+2, 478);
  for i := 1 to 6 do Line(1, i*79+3, 3, i*79+3);
  SetColor(Brown);                          { (0, 0) equ (2, 477) }
  OutTextXY(9, 395, '100');
  OutTextXY(9, 315, '200');
  OutTextXY(9, 237, '300');
  OutTextXY(9, 157, '400');
  OutTextXY(9, 80, '500');
  OutTextXY(99, 465, '1');
  OutTextXY(199, 465, '2');
  OutTextXY(299, 465, '3');
  OutTextXY(399, 465, '4');
  OutTextXY(499, 465, '5');
  OutTextXY(630, 465, 't');
  OutTextXY(9, 3, 'x');
  SetColor(Red);
  OutTextXY(9, 465, '0');
  OutTextXY(599, 465, '6');
  OutTextXY(9, 30, '553.82706');
end;
{ Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û=Û }
begin
  D:=Detect;
  InitGraph(D,R,'');
  e:=GraphResult;
  if e <> 0 then
    begin
      WriteLn('Îøèáêà ãðàôèêè(', e, '):');
      WriteLn(GraphErrorMsg(e));
      Halt;
    end;
  eps := 0.5E-2 ;
  t := t0-0.5;
  DoScreen;
  C := exp(4.0)*(49836.0/4913.0);
  C1:=52.0/289.0;
  C2:=242.0/289.0;
  C3:=706.0/4913.0;
  C4:=3710.0/4913.0;
  SetColor(Green);
  SetLineStyle(1,3,1);
  Line(0, Round(477.0-Sx*f1(2.0)), 220, Round(477.0-Sx*f1(2.0)));
  Line(Round(2.0+St*2.0), 30, Round(2.0+St*2.0), 479);
  SetLineStyle(0,1,1);
  While (t<=b+0.5) do
    begin
      x:=f1(t);
      t := t+0.001;
      PutPixel(Round(2.0+St*t),Round(477.0-Sx*x), White);
      if Round(t*100) mod 30 = 0 then
      Line(Round(2.0+St*t),Round(477.0-Sx*x)+3, Round(2.0+St*t), 477);
    end;
  x := x0;
  t := t0;
{Ñàìîå ñìåøíîå, ñ ÏÎÑÒÎßÍÍÛÌ øàãîì h = 0.001  ðèñóåò íàìíîãî áûñòðåå}
{ è ïðè ýòîì ÒÀÊÆÅ íàáëþäàþòñÿ íåçíà÷èòåëüíûå îòêëîíåíèÿ}
  h := h0;
  Sn := 0.0;
  N := 0;
  NN :=1;
  if MaxAvail>=SizeOf(TRslt)
    then
      GetMem(Rslt, SizeOf(TRslt));
  SetColor(Yellow);
  Assign(ff, 'difur.out');
  ReWrite(ff);
  OutTextXY(320, 10, ' t        Òî÷í. çí.         Ïðèáë. çí.');
  SetColor(LightGray);
  While t <= b do
    begin
     Repeat
      tt := t+h/2.0;
      k1 := h * f(t, x)/2.0;
      k2 := h * f(t+h, x+k1/2.0)/2.0;
      k3 := h * f(t+h, x-k1+2.0*k2)/2.0;
      S := (k1+4.0*k2+k3)/6.0;
      x1 := x + S;
      k1 := h * f(tt, x)/2.0;
      k2 := h * f(tt+h/2.0, x+k1/2.0)/2.0;
      k3 := h * f(tt+h/2.0, x-k1+2.0*k2)/2.0;
      S := (k1+4.0*k2+k3)/6.0;
      xk := x1 + S;
      delta := Abs((xk-x)/7.0);
      if delta>eps then
         h := h/2.0;
     Until delta < eps;
     if 16.0*delta < eps then h := h * 2.0;
{      if Round(t*100) mod 10 = 0 then
        begin
           SetColor(Black);
           OutTextXY(1,1,'ÛÛÛÛÛÛÛÛÛ');
           OutTextXY(1,30,'ÛÛÛÛÛÛÛÛÛ');
           Str(delta:5:5, SSS);
           SetColor(White);
           OutTextXY(1,1,SSS);
           Str(h:5:5, SSS);
           OutTextXY(1,30,SSS);
        end;
 }
      t := t + h;
      k1 := h * f(t, x);
      k2 := h * f(t+h/2.0, x+k1/2.0);
      k3 := h * f(t+h, x-k1+2.0*k2);
      S := (k1+4.0*k2+k3)/6.0;
      x1 :=x;
      x := x+S;
      N := N + 1;
      Write(ff, t:5:5);
      Write(ff, '               ');
      Write(ff, f1(t):5:5);
      Write(ff, '               ');
      WriteLn(ff, x:5:5);
      Sn := Sn + x*h;
      if Round(t*10000) mod 2400 = 0 then
        if NN <= 24 then
            begin
             ViewData(t, f1(t), x);
             inc(NN);
            end;
      PutPixel(Round(2.0+St*t),Round(477.0-Sx*x), LightRed);
    end;
  Close(ff);
  ReadKey;
  CloseGraph;
{  h := 0.001;
  t := 0.0;
  WriteLn('Ãðàôèê: <S> = ',Sn:5:5);
  Sn := f1(t);
  While t <= b do
  begin
    t := t+h;
    Sn := Sn + f1(t);
  end;
  Sn := Sn*h;
  WriteLn('Ðàññ÷èòûâàÿ: <S> = ',Sn:5:5);}
  i := 1;
  DataRead(i);
  ScreenData(i);
  Repeat
   Key := ReadKey;
   case Key of
    #0: case ReadKey of
         #72 :  {Up}
            begin
              if (i>1) then
                begin
                  dec(i);
                  if (i mod 100 = 99) or (i=1) then DataRead(i-77);
                  ScreenData(((i-1) mod 100)+1);
                end;
            end;
         #80 :  {Dn}
            begin
              if i22 then
              begin
               i := i - 22;
               DataRead(i);
               ScreenData(((i-1) mod 100)+1);
              end
            end;
         #81 :  {PgDn}
            begin
             if i

Íàçàä