Advertisement
DarkDevourer

Практика - задание 2 (нет графики - Pascal)

Jun 30th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function func(x: double) : double;
  2. begin
  3. Result := x * exp(x)*sin(x);;
  4. end;
  5.  
  6. function f2(x, h: double) : double;
  7. begin
  8. Result := (func(x + h) - 2 * func(x) + func(x - h)) / (h * h);
  9. end;
  10.  
  11. var
  12. n, i: integer;
  13. a, b, h, e, S, f2max, check, fa, fb, fx, f2n: double;
  14. conv: string;
  15. begin
  16. a := 0; b:= 1; n:= 48; e:= 0.001;
  17. writeln('Нахождение определенного интеграла функции f(x)=x*e^(x)*sin(x) на отрезке [0;1]. Отрезок разбивается на 48 частей.');
  18. while (true) do
  19. begin
  20. h := (b - a) / n;
  21. fa:=func(a);
  22. fb:=func(b);
  23. S:= h * (fa + fb) / 2;
  24. for i:= 0 to n - 1 do
  25. begin
  26. fx:=func(a + h * i);
  27. S := S + fx*h;
  28. end;
  29. f2max:= f2(a, h);
  30. for i:= 0 to n - 1 do
  31. begin;
  32. f2n:=f2(a + h * i, h);
  33. if f2n > f2max then f2max:= f2n;
  34. end;
  35. check:= f2max * power(b - a, 3) / (12 * n*n);
  36. if check > e then n := n + 5
  37. else
  38. begin
  39. writeln('Значение интеграла = ', S);
  40. break;
  41. end;
  42. end;
  43. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement