intge2te.pas 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. program InitInfEx;
  2. uses
  3. Typ,
  4. Spe,
  5. Int;
  6. var
  7. num2: ArbInt;
  8. inte: ArbFloat;
  9. const
  10. e = 2.71828182845905;
  11. function cx(x: ArbFloat): ArbFloat;
  12. begin
  13. cx := cos(x) / (sqr(x) + 1);
  14. end;
  15. function pcx(x: ArbFloat): ArbFloat;
  16. begin
  17. pcx := 2 * x * sin(x) / sqr(sqr(x) + 1);
  18. end;
  19. function ppcx(x: ArbFloat): ArbFloat;
  20. var
  21. s: ArbFloat;
  22. begin
  23. s := sqr(x);
  24. ppcx := cos(x) * (2 - 6 * s) / ((s + 1) * sqr(s + 1));
  25. end;
  26. function cc2(x: ArbFloat): ArbFloat;
  27. var
  28. x2: ArbFloat;
  29. begin
  30. x2 := sqr(x);
  31. cc2 := cos(x) / (sqr(x2) + x2 + 1);
  32. end;
  33. function ucx(x: ArbFloat): ArbFloat;
  34. begin
  35. if x = 0 then
  36. ucx := 0
  37. else
  38. ucx := cx((1 - x) / x) / sqr(x);
  39. end;
  40. function ucc2(x: ArbFloat): ArbFloat;
  41. begin
  42. if x = 0 then
  43. ucc2 := 0
  44. else
  45. ucc2 := cc2((1 - x) / x) / sqr(x);
  46. end;
  47. function uz(x: ArbFloat): ArbFloat;
  48. begin
  49. uz := sin(x) * exp(-x);
  50. end;
  51. function ss1(x: ArbFloat): ArbFloat; { f(«n(n-1))=0 (n=1,2,3,...) }
  52. var
  53. n, s, c: ArbFloat; { f(«ný)=2/(ný(n+1)) }
  54. begin { overigens: f linear interpoleren}
  55. s := sqrt(2 * x);
  56. n := trunc(s);
  57. if n * (n + 1) / 2 <= x then
  58. n := n + 1; { n z.d.d. «n(n-1) ó x ó «n(n-1) }
  59. c := 4 / (n * sqr(n) * (n + 1));
  60. if s < n then
  61. ss1 := c * (x - n * (n - 1) / 2)
  62. else
  63. ss1 := c * (n * (n + 1) / 2 - x);
  64. end;
  65. function ss2(x: ArbFloat): ArbFloat; { als ss1 met f(«ný)=2/(n.2ü) }
  66. var
  67. n, s, c: ArbFloat;
  68. begin
  69. s := sqrt(2 * x);
  70. n := trunc(s);
  71. if n * (n + 1) / 2 <= x then
  72. n := n + 1;
  73. c := spepow(2, 2 - n) / sqr(n);
  74. if s < n then
  75. ss2 := c * (x - n * (n - 1) / 2)
  76. else
  77. ss2 := c * (n * (n + 1) / 2 - x);
  78. end;
  79. function ss3(x: ArbFloat): ArbFloat; { x z.d.d. «.2ü ó x+1 ó 2ü s=2ü}
  80. var
  81. s, c, f, x1: ArbFloat;
  82. n: ArbInt; {n even: f(n)=-4/(n.2ü)}
  83. begin {n oneven: f(n) = 4/(n.2ü)}
  84. n := 0;
  85. s := 1;
  86. x1 := x + 1; { overigens: f lineair interpol.}
  87. repeat
  88. n := n + 1;
  89. s := s * 2
  90. until s > x1;
  91. c := 16 / (n * sqr(s));
  92. if x1 < 0.75 * s then
  93. f := c * (x1 - s / 2)
  94. else
  95. f := c * (s - x1);
  96. if odd(n) then
  97. ss3 := f
  98. else
  99. ss3 := -f;
  100. end;
  101. function ss4(x: ArbFloat): ArbFloat; { 0 ó x ó 1}
  102. var
  103. y, h: ArbFloat; { zij x = ä [1:ì] c(n)/3ü c(n)=0,1,2}
  104. ready: boolean; { zoek kleinste k met c(k)=1}
  105. begin { dan geldt f(x)=u(y)/3k }
  106. y := 3 * x;
  107. h := 1 / 3;
  108. ready := False; { met u(y)=|y-1«|, 1 ó y ó 2}
  109. repeat { en y = ä [k:ì] (c(n)/3ü)*3k }
  110. if (y < 1) or (y > 2) then
  111. begin
  112. if y < 1 then
  113. y := 3 * y
  114. else
  115. y := 3 * (y - 2);
  116. h := h / 3;
  117. if h < macheps then
  118. begin
  119. ready := True;
  120. ss4 := 0;
  121. end;
  122. end
  123. else
  124. begin
  125. ready := True;
  126. if y < 1.5 then
  127. ss4 := h * (y - 1)
  128. else
  129. ss4 := h * (2 - y);
  130. end
  131. until ready;
  132. end;
  133. function ss5(x: ArbFloat): ArbFloat; { uitbreiding ss4}
  134. var
  135. y, h: ArbFloat; {functiewaarden op 'volgend' interval}
  136. ready: boolean; { [n, n+1] telkens halveren}
  137. begin
  138. y := 3 * frac(x);
  139. h := spepow(0.5, trunc(x)) / 3;
  140. ready := False;
  141. repeat
  142. if (y < 1) or (y > 2) then
  143. begin
  144. if y < 1 then
  145. y := 3 * y
  146. else
  147. y := 3 * (y - 2);
  148. h := h / 3;
  149. if h < macheps then
  150. begin
  151. ready := True;
  152. ss5 := 0;
  153. end;
  154. end
  155. else
  156. begin
  157. ready := True;
  158. if y < 1.5 then
  159. ss5 := h * (y - 1)
  160. else
  161. ss5 := h * (2 - y);
  162. end
  163. until ready;
  164. end;
  165. function ss6(x: ArbFloat): ArbFloat; { 0 ó x ó 1, 'gladdere' variant van ss4}
  166. var
  167. y, h: ArbFloat;
  168. ready: boolean;
  169. function f(y: ArbFloat): ArbFloat; { 1 ó y ó 2, 1 x cont. diff, symm. max in 1.5}
  170. begin
  171. if y > 1.5 then
  172. y := 3 - y;
  173. if y < 1.25 then
  174. f := sqr(y - 1)
  175. else
  176. f := 0.125 - sqr(1.5 - y);
  177. end;
  178. begin
  179. y := 3 * x;
  180. h := 1 / 3;
  181. ready := False;
  182. repeat
  183. if (y < 1) or (y > 2) then
  184. begin
  185. if y < 1 then
  186. y := 3 * y
  187. else
  188. y := 3 * (y - 2);
  189. h := h / 3;
  190. if h < macheps then
  191. begin
  192. ready := True;
  193. ss6 := 0;
  194. end;
  195. end
  196. else
  197. begin
  198. ready := True;
  199. ss6 := h * f(y);
  200. end
  201. until ready;
  202. end;
  203. function bb(x: ArbFloat): ArbFloat;
  204. begin
  205. bb := spepow(x, -x) * (ln(x) + 1);
  206. end;
  207. var
  208. integral, ae, err: ArbFloat;
  209. term: ArbInt;
  210. intex: boolean;
  211. procedure Header;
  212. begin
  213. Write('int': num2, '': numdig - num2, ' ', 'err': 7, ' ': 4);
  214. if intex then
  215. Write('f': 6);
  216. writeln;
  217. end;
  218. procedure ShowResults;
  219. var
  220. f: ArbFloat;
  221. begin
  222. if intex then
  223. f := inte - integral;
  224. case term of
  225. 1:
  226. begin
  227. Write(integral: numdig, ' ', err: 10, ' ');
  228. if intex then
  229. writeln(f: 10)
  230. else
  231. writeln;
  232. end;
  233. 2:
  234. begin
  235. Write(integral: numdig, ' ', err: 10, ' ');
  236. if intex then
  237. writeln(f: 10)
  238. else
  239. writeln;
  240. Writeln(' process afgebroken, te hoge nauwkeurigheid?');
  241. end;
  242. 3: Writeln('Verkeerde parameterwaarde (<=0) bij aanroep: ', ae: 8);
  243. 4:
  244. begin
  245. Write(integral: numdig, ' ', err: 10, ' ');
  246. if intex then
  247. writeln(f: 10)
  248. else
  249. writeln;
  250. writeln(' process afgebroken, moeilijk, mogelijk divergent?');
  251. end;
  252. end;
  253. end;
  254. begin
  255. num2 := numdig div 2;
  256. Writeln(' ì ');
  257. Writeln(' ô cos x ã ');
  258. Writeln(' ³ ------- dx = -- ');
  259. Writeln(' 0 õ xý+ 1 2e ');
  260. writeln;
  261. ae := 1e-8;
  262. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  263. writeln;
  264. inte := 0.5 * pi / e;
  265. intex := True;
  266. writeln(inte: numdig, ' is ''exacte'' oplossing');
  267. Int1fr(@cx, 0, infinity, ae, integral, err, term);
  268. Header;
  269. ShowResults;
  270. writeln;
  271. Writeln('berekend met Int1fr via transformatie x=(1-t)/t');
  272. writeln;
  273. Int1fr(@ucx, 0, 1, ae, integral, err, term);
  274. Header;
  275. ShowResults;
  276. Writeln(' ì ');
  277. Writeln(' ô 2x sin x ã ');
  278. Writeln(' ³ --------- dx = -- ');
  279. Writeln(' 0 õ (xý+ 1)ý 2e ');
  280. writeln;
  281. ae := 1e-8;
  282. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  283. writeln;
  284. Int1fr(@pcx, 0, infinity, ae, integral, err, term);
  285. Header;
  286. ShowResults;
  287. Writeln(' ì ');
  288. Writeln(' ô (2-6xý)cos x ã ');
  289. Writeln(' ³ ------------ dx = -- ');
  290. Writeln(' 0 õ (xý+ 1)3 2e ');
  291. writeln;
  292. ae := 1e-8;
  293. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  294. writeln;
  295. Int1fr(@ppcx, 0, infinity, ae, integral, err, term);
  296. Header;
  297. ShowResults;
  298. Writeln(' ì ');
  299. Writeln(' ô cos x ');
  300. Writeln(' ³ ------------ dx = (ã/û3) exp(-«û3) sin(ã/6+«) ');
  301. Writeln(' 0 õ (xý)ý+xý+ 1 ');
  302. writeln;
  303. writeln;
  304. ae := 1e-8;
  305. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  306. writeln;
  307. inte := (pi / sqrt(3)) * exp(-sqrt(0.75)) * sin(pi / 6 + 0.5);
  308. writeln(inte: numdig, ' is ''exacte'' oplossing');
  309. Int1fr(@cc2, 0, infinity, ae, integral, err, term);
  310. Header;
  311. ShowResults;
  312. writeln;
  313. Writeln('berekend met Int1fr via transformatie x=(1-t)/t');
  314. writeln;
  315. writeln;
  316. writeln(inte: numdig, ' is ''exacte'' oplossing');
  317. Int1fr(@ucc2, 0, 1, ae, integral, err, term);
  318. Header;
  319. ShowResults;
  320. Writeln(' ì ');
  321. Writeln(' ô sin u ');
  322. Writeln(' ³ ------ du = « ');
  323. Writeln(' õ exp(u) ');
  324. writeln(' 0 ');
  325. ae := 1e-8;
  326. intex := True;
  327. inte := 0.5;
  328. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  329. writeln;
  330. Int1fr(@uz, 0, infinity, ae, integral, err, term);
  331. Header;
  332. ShowResults;
  333. writeln(' functie ss1; int = ä {1:ì}1/n(n+1) = 1');
  334. ae := 1e-8;
  335. intex := True;
  336. inte := 1;
  337. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  338. int1fr(@ss1, 0, infinity, ae, integral, err, term);
  339. Header;
  340. Showresults;
  341. writeln(' functie ss2; int = ä {1:ì} («)ü = 1');
  342. ae := 1e-8;
  343. intex := True;
  344. inte := 1;
  345. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  346. int1fr(@ss2, 0, infinity, ae, integral, err, term);
  347. Header;
  348. Showresults;
  349. writeln(' functie ss3; int = ä {1:ì} (-1)ü/n = ln(2)');
  350. ae := 1e-8;
  351. intex := True;
  352. inte := ln(2);
  353. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  354. int1fr(@ss3, 0, infinity, ae, integral, err, term);
  355. Header;
  356. Showresults;
  357. writeln(' functie ss4 (op [0,1]); int = 1/28 ');
  358. ae := 1e-8;
  359. intex := True;
  360. inte := 1 / 28;
  361. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  362. int1fr(@ss4, 0, 1, ae, integral, err, term);
  363. Header;
  364. Showresults;
  365. writeln(' functie ss5 (op [0,ì)); int = 1/14 ');
  366. ae := 1e-8;
  367. intex := True;
  368. inte := 1 / 14;
  369. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  370. int1fr(@ss5, 0, infinity, ae, integral, err, term);
  371. Header;
  372. Showresults;
  373. writeln(' functie ss6 (op [0,1]); int = 1/112 ');
  374. ae := 1e-8;
  375. intex := True;
  376. inte := 1 / 112;
  377. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  378. int1fr(@ss6, 0, 1, ae, integral, err, term);
  379. Header;
  380. Showresults;
  381. Writeln(' ì ');
  382. Writeln(' ô ln(x)+1 ');
  383. Writeln(' ³ ---------- dx = 1 ');
  384. Writeln(' õ xx ');
  385. writeln(' 1 ');
  386. ae := 1e-8;
  387. intex := True;
  388. inte := 1;
  389. Writeln(' Gevraagde nauwkeurigheid', ae: 12);
  390. writeln;
  391. Int1fr(@bb, 0, infinity, ae, integral, err, term);
  392. Header;
  393. ShowResults;
  394. end.