Advertisement
NyanCoder

Euler-Cauchy.pas

May 23rd, 2022
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uses math;
  2.  
  3. const
  4.     x0 = 0;
  5.     y0 = 1;
  6.     b = 1;
  7.     h = 0.01;
  8.  
  9. function f(x, y : real) : real;
  10. begin
  11.     f := x*y;
  12. end;
  13.  
  14. function Y_(x : real) : real;
  15. begin
  16.     Y_ := exp(x*x/2);
  17. end;
  18.  
  19. var
  20.     i, n : integer;
  21.     x, y, y_star, myF : real;
  22.  
  23. begin
  24.     n := trunc((b - x0) / h);
  25.  
  26.     x := x0;
  27.     y := y0;
  28.     for i := 1 to n do begin
  29.         myF := f(x, y);
  30.         y_star := y + myF * h;
  31.         x := x0 + i*h;
  32.         y += (myF + f(x, y_star)) * h / 2;
  33.     end;
  34.  
  35.     writeln(abs(Y_(b) - y):0:6);
  36. end.
Advertisement
RAW Paste Data Copied
Advertisement