program RK4SEG;
uses printer;
var
  T,X,Y,H,HS2,R1,R2,R3,R4,X0,Y0,T0,V,DELTAT:real;
  XA,XB,XC,XD,YA,YB,YC,YD,R :real;
  R1X,R2X,R3X,R4X,R1Y,R2Y,R3Y,R4Y,RX,RY :real;
  N,I,J :integer;
  NOVO :string[1];
  TITULO :string[70];
function FUNCAOF(T,X,Y:real) :real;
begin
  FUNCAOF := Y
end;
function FUNCAOG(T,X,Y:real) :real;
begin
  FUNCAOG := (0.6*sin(2.0*T)-1.6*Y-24.0*X)*2.01078
end;
begin
  writeln('Indique o sistema de equacoes diferenciais a ser resolvido');
  readln(TITULO);writeln(Lst,TITULO);
  writeln('Forneca T0 , X0 , Y0 e o PASSO ');
  write('T0 = ');readln(T0);
  write('X0 = ');readln(X0);
  write('Y0 = ');readln(Y0);
  write('PASSO  = ');readln(DELTAT);
repeat
  T := T0; X := X0; Y := Y0;
  write(Lst,'T0 = ',T0:14:10,'    X0 = ',X0:14:10,'    Y0 = ',Y0:14:10);
  writeln(' Forneca o numero de divisoes do PASSO');
  write(' N  = ');readln(N);H := DELTAT / N;HS2 := H/2;
  writeln(Lst,' N = ',N:4);
  for J := 1 to 10 do begin
  for I := 1 to N do begin
    R1X := FUNCAOF(T,X,Y);R1Y := FUNCAOG(T,X,Y);
    XA := X + R1X * HS2; YA := Y + R1Y * HS2; T := T + HS2;
    R2X := FUNCAOF(T,XA,YA); R2Y := FUNCAOG(T,XA,YA);
    XB := X + R2X * HS2; YB := Y + R2Y * HS2;
    R3X := FUNCAOF(T,XB,YB); R3Y := FUNCAOG(T,XB,YB);
    XC := X + R3X * H;   YC := Y + R3Y * H;  T := T + HS2;
    R4X := FUNCAOF(T,XC,YC); R4Y := FUNCAOG(T,XC,YC);
    RX := (R1X + 2*R2X + 2*R3X + R4X)/6;
    RY := (R1Y + 2*R2Y + 2*R3Y + R4Y)/6;
    X := X + RX * H; Y := Y + RY * H;
                      end;
  writeln(Lst,'T = ',T:14:10,'     X = ',X:14:10,'     Y = ',Y:14:10);
                       end;
    write('Tecle S se deseja novo calculo ');readln(NOVO);writeln(Lst,' ');
until NOVO <> 'S'
end.
{ fim do RK4SEG }


