program RK4;
uses printer;
var
  X,Y,H,HS2,R1,R2,R3,R4,X0,Y0,V,DELTAX,YA,YB,YC,YD,R :extended;
  N,I,J :integer;
  NOVO :string[1];
  TITULO :string[70];
function FUNCAO(X:extended;Y:extended) :extended;
begin
  FUNCAO := X + Y
end;
begin
  writeln('Indique a equacao diferencial a ser resolvida ');
  readln(TITULO);writeln(Lst,TITULO);
  writeln('Forneca X0 , Y0 e o PASSO ');
  write('X0 = ');readln(X0);
  write('Y0 = ');readln(Y0);
  write('PASSO  = ');readln(DELTAX);
repeat
  X := X0; Y := Y0;
  write(Lst,'X0 = ',X0:14:10,'    Y0 = ',Y0:14:10);
  writeln(' Forneca o numero de divisoes do PASSO');
  write(' N  = ');readln(N);H := DELTAX / N;HS2 := H/2;
  writeln(Lst,' N = ',N:4);
  for J := 1 to 10 do begin
  for I := 1 to N do begin
    R1 := FUNCAO(X,Y); X := X + HS2; YA := Y + R1 * HS2;R2 := FUNCAO(X,YA);
    YB := Y + R2 * HS2;R3 := FUNCAO(X,YB);YC := Y + R3 * H;X := X + HS2;
    R4 := FUNCAO(X,YC);R := (R1+2*R2+2*R3+R4)/6;
    Y := Y + R * H;
    V:= 2 * exp(X) - X - 1;
                      end;
  writeln(Lst,'X = ',X:14:10,'     Y = ',Y:14:10,'     YC = ',V:14:10);
                       end;
    write('Tecle S se deseja novo calculo ');readln(NOVO);writeln(Lst,' ');
until NOVO <> 'S'
end.
{ fim do RK4 }
