Advertisement
DarkDevourer

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

Jun 29th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. Uses GraphABC;
  2.  
  3. function func(x: double): double;
  4. begin
  5. Result:=x * exp(x)*sin(x);;
  6. end;
  7.  
  8. function f2(x, h: double): double;
  9. begin
  10. Result:=(func(x + h) - 2 * func(x) + func(x - h)) / (h * h);
  11. end;
  12.  
  13. var
  14. n, w, h, height, length, mastx, masty, i: integer;
  15. a, b, h1, e, S, f2max, i1, check, maxfunc: double;
  16. conv: string;
  17. begin
  18. w:=1900; h:=1000; length:= w - 50; height:= h - 100; a:= 0; b:= 1; n:=48; e:=0.001;
  19. setwindowwidth(w);
  20. setwindowheight(h);
  21. writeln('Нахождение определенного интеграла функции f(x)=x*e^(x)*sin(x) на отрезке [0;1]. Отрезок разбивается на 48 частей.');
  22. while(true) do
  23. begin
  24. h1:= (b - a) / n;
  25. S:= h1 * (func(a) + func(b)) / 2;
  26. for i:=0 to n-1 do
  27. S:= S + func(a + h1 * i)*h1;
  28. f2max:= f2(a, h1);
  29. for i:=0 to n-1 do
  30. if f2(a + h1 * i, h1) > f2max then f2max:= f2(a + h1 * i, h1);
  31. check:=f2max * power(b - a, 3) / (12 * n*n);
  32. if check>e then n:= n + 5
  33. else
  34. begin
  35. writeln('Значение интеграла = ', S);
  36. break;
  37. end;
  38. end;
  39. mastx:= floor(length/n);
  40. maxfunc:= func(a);
  41. for i:=0 to n-1 do
  42. if (func(a + i * h1) > maxfunc) then
  43. maxfunc:= func(a + i * h1);
  44. if (func(b) > maxfunc) then
  45. maxfunc:= func(b);
  46. masty:= floor(height / maxfunc);
  47. writeln('Нажмите Enter, чтобы вывести диаграмму.');
  48. readln();
  49. ClearWindow;
  50. line(30, 30, 30, 30 + height);
  51. line(30, 30, 25, 40);
  52. line(30, 30, 35, 40);
  53. line(30, 30 + height, 20 + length, 30 + height);
  54. line(20 + length, 30 + height, length + 15, 25 + height);
  55. line(20 + length, 30 + height, length + 15, 35 + height);
  56. textout(length + 20, 45 + height, 'x');
  57. textout(40, 30, 'f(x)');
  58. i1:=0;
  59. while i1<1 do
  60. begin
  61. line(30 + floor(i1 * length), 20 + height, 30 + floor(i1 * length), 40 + height);
  62. conv:=floattostr(i1);
  63. textout(30 + floor(i1 * length), 45 + height, conv);
  64. line(20, 30 + height - floor(func(i1) * masty), 40, 30 + height - floor(func(i1) * masty));
  65. conv:=floattostr(func(i1));
  66. textout(5, 30 + height - floor(func(i1) * masty), conv);
  67. i1:=i1+0.2;
  68. end;
  69. for i:=0 to n-1 do
  70. begin
  71. line(30 + floor(i * mastx), 30 + height, 30 + floor(i * mastx), 30 + height - floor(func(a+i*h1) * masty));
  72. line(30 + floor(i * mastx), 30 + height - floor(func(a+i*h1) * masty), 30 + floor((i+1) * mastx), 30 + height - floor(func(a+i*h1) * masty));
  73. line(30 + floor((i+1) * mastx), 30 + height, 30 + floor((i+1) * mastx), 30 + height - floor(func(a+i*h1) * masty));
  74. end;
  75. readln();
  76. ClearWindow;
  77. writeln('Нажмите Enter, чтобы вывести график функции.');
  78. readln();
  79. ClearWindow;
  80. line(30, 30, 30, 30 + height);
  81. line(30, 30, 25, 40);
  82. line(30, 30, 35, 40);
  83. line(30, 30 + height, 20 + length, 30 + height);
  84. line(20 + length, 30 + height, length + 15, 25 + height);
  85. line(20 + length, 30 + height, length + 15, 35 + height);
  86. textout(length + 20, 45 + height, 'x');
  87. textout(40, 30, 'f(x)');
  88. i1:=0;
  89. while i1<1 do
  90. begin
  91. line(30 + floor(i1 * length), 20 + height, 30 + floor(i1 * length), 40 + height);
  92. conv:=floattostr(i1);
  93. textout(30 + floor(i1 * length), 45 + height, conv);
  94. line(20, 30 + height - floor(func(i1) * masty), 40, 30 + height - floor(func(i1) * masty));
  95. conv:=floattostr(func(i1));
  96. textout(5, 30 + height - floor(func(i1) * masty), conv);
  97. i1:=i1+0.2;
  98. end;
  99. for i:=0 to n-1 do
  100. begin
  101. line(30 + floor(i * mastx), 30 + height - floor(func(a+i*h1) * masty), 30 + floor((i+1) * mastx), 30 + height - floor(func(a+(i+1)*h1) * masty));
  102. end;
  103. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement