roofnrt1.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. program Roofnrte;
  2. uses
  3. typ,
  4. roo;
  5. type
  6. maxarray = array[1..128] of ArbFloat;
  7. var
  8. n: ArbInt;
  9. a: ArbFloat;
  10. ah2: ArbFloat;
  11. procedure PraktikumEx(var x, fx: ArbFloat; var deff: boolean);
  12. var
  13. xloc: maxarray absolute x;
  14. floc: maxarray absolute fx;
  15. i: ArbInt;
  16. begin
  17. floc[1] := 2 * (xloc[1] - xloc[2]) - ah2 * exp(xloc[1]);
  18. for i := 2 to n - 1 do
  19. floc[i] := -xloc[i - 1] + 2 * xloc[i] - xloc[i + 1] - ah2 * exp(xloc[i]);
  20. floc[n] := -xloc[n - 1] + 2 * xloc[n] - ah2 * exp(xloc[n]);
  21. end;
  22. const
  23. m = 9;
  24. procedure NagExample(var x, fx: ArbFloat; var deff: boolean);
  25. var
  26. xloc: array[1..m] of ArbFloat absolute x;
  27. floc: array[1..m] of ArbFloat absolute fx;
  28. k: ArbInt;
  29. begin
  30. floc[1] := 1 + (3 - 2 * xloc[1]) * xloc[1] - 2 * xloc[2];
  31. for k := 2 to m - 1 do
  32. floc[k] := 1 + (3 - 2 * xloc[k]) * xloc[k] - xloc[k - 1] - 2 * xloc[k + 1];
  33. floc[m] := 1 + (3 - 2 * xloc[m]) * xloc[m] - xloc[m - 1];
  34. end;
  35. procedure MatlabEx(var x, fx: ArbFloat; var deff: boolean);
  36. var
  37. xloc: array[1..3] of ArbFloat absolute x;
  38. floc: array[1..3] of ArbFloat absolute fx;
  39. begin
  40. floc[1] := sin(xloc[1]) + sqr(xloc[2]) + ln(xloc[3]) - 7;
  41. floc[2] := 3 * xloc[1] + exp(xloc[2] * ln(2)) - xloc[3] * sqr(xloc[3]) + 1;
  42. floc[3] := xloc[1] + xloc[2] + xloc[3] - 5;
  43. end;
  44. procedure TPNumlibEx(var x, fx: ArbFloat; var deff: boolean);
  45. begin
  46. fx := cos(x);
  47. end;
  48. procedure JdeJongEx(var x, fx: ArbFloat; var deff: boolean);
  49. begin
  50. if (x >= 0) and (x <= 1) then
  51. fx := x - 2
  52. else
  53. deff := False;
  54. end;
  55. procedure Uitvoer(var x1: ArbFloat; n, step: ArbInt);
  56. var
  57. i: ArbInt;
  58. xloc: maxarray absolute x1;
  59. begin
  60. i := 1;
  61. while (i <= n) do
  62. begin
  63. writeln(i: 5, ' ', xloc[i]: 20);
  64. Inc(i, step);
  65. end;
  66. writeln;
  67. end;
  68. var
  69. x: ^maxarray;
  70. t, residu: ArbFloat;
  71. i, term: ArbInt;
  72. begin
  73. { praktikum sommetje }
  74. n := 8;
  75. a := 0.50;
  76. repeat
  77. ah2 := a / sqr(n);
  78. GetMem(x, n * SizeOf(ArbFloat));
  79. for i := 1 to n do
  80. x^[i] := 0;
  81. writeln('Voorbeeld programma ''praktikum'', resultaten voor n= ', n: 2);
  82. writeln;
  83. roofnr(@PraktikumEx, n, x^[1], residu, 1e-4, term);
  84. if term = 1 then
  85. writeln(' Norm van de residuen', residu: 20, #13#10,
  86. ' Berekende oplossing')
  87. else
  88. writeln(' Proces afgebroken term = ', term, #13#10,
  89. ' Laatst berekende waarden');
  90. writeln;
  91. Uitvoer(x^[1], n, n div 8);
  92. FreeMem(x, n * SizeOf(ArbFloat));
  93. n := n * 2
  94. until n = 128;
  95. { Nag procedure bibliotheek voorbeeld }
  96. GetMem(x, m * SizeOf(ArbFloat));
  97. for i := 1 to m do
  98. x^[i] := -1;
  99. writeln('Voorbeeld programma ''NAG-bibliotheek'' met m= ', m: 2);
  100. writeln;
  101. roofnr(@NagExample, m, x^[1], residu, 1e-6, term);
  102. if term = 1 then
  103. writeln(' Norm van de residuen', residu: 20, #13#10,
  104. ' Berekende oplossing')
  105. else
  106. writeln(' Proces afgebroken term = ', term, #13#10,
  107. ' Laatst berekende waarden');
  108. writeln;
  109. Uitvoer(x^[1], m, 1);
  110. FreeMem(x, m * SizeOf(ArbFloat));
  111. { Matlab voorbeeld uit handleiding }
  112. n := 3;
  113. GetMem(x, n * SizeOf(ArbFloat));
  114. for i := 1 to n do
  115. x^[i] := 1;
  116. writeln('Voorbeeld programma ''MATLAB handleiding'', resultaten voor n= ', n: 2);
  117. writeln;
  118. roofnr(@MatlabEx, n, x^[1], residu, 1e-6, term);
  119. if term = 1 then
  120. writeln(' Norm van de residuen', residu: 20, #13#10,
  121. ' Berekende oplossing')
  122. else
  123. writeln(' Proces afgebroken term = ', term, #13#10,
  124. ' Laatst berekende waarden');
  125. writeln;
  126. Uitvoer(x^[1], n, 1);
  127. FreeMem(x, n * SizeOf(ArbFloat));
  128. { 1-dimensionaal voorbeeld uit TPNumlib }
  129. writeln('Voorbeeld programma ''TPNumlib'' voor ‚‚n dimensie');
  130. writeln;
  131. t := 1;
  132. roofnr(@TPNumlibEx, 1, t, residu, 1e-6, term);
  133. if term = 1 then
  134. writeln(' Norm van de residuen', residu: 20, #13#10,
  135. ' Berekende oplossing')
  136. else
  137. writeln(' Proces afgebroken term = ', term, #13#10,
  138. ' Laatst berekende waarden');
  139. writeln;
  140. Writeln(' ', t: 20);
  141. { Matlab voorbeeld uit handleiding }
  142. { dit moet fout gaan }
  143. n := 3;
  144. GetMem(x, n * SizeOf(ArbFloat));
  145. for i := 1 to n do
  146. x^[i] := 1;
  147. writeln;
  148. writeln('Voorbeeld programma ''MATLAB handleiding'', resultaten voor n= ', n: 2);
  149. writeln('Gaat niet goed want de relatieve fout is gelijk aan 0 gekozen');
  150. writeln;
  151. roofnr(@MatlabEx, n, x^[1], residu, 0, term);
  152. if term = 1 then
  153. writeln(' Norm van de residuen', residu: 20, #13#10,
  154. ' Berekende oplossing')
  155. else
  156. writeln(' Proces afgebroken term = ', term, #13#10,
  157. ' Laatst berekende waarden');
  158. writeln;
  159. Uitvoer(x^[1], n, 1);
  160. writeln;
  161. writeln('Voorbeeld programma ''MATLAB handleiding'', resultaten voor n= ', n: 2);
  162. writeln;
  163. for i := 1 to n do
  164. x^[i] := 1;
  165. roofnr(@MatlabEx, n, x^[1], residu, 1e-8, term);
  166. if term = 1 then
  167. writeln(' Norm van de residuen', residu: 20, #13#10,
  168. ' Berekende oplossing')
  169. else
  170. writeln(' Proces afgebroken term = ', term, #13#10,
  171. ' Laatst berekende waarden');
  172. writeln;
  173. Uitvoer(x^[1], n, 1);
  174. FreeMem(x, n * SizeOf(ArbFloat));
  175. { 1-dimensionaal voorbeeld voor deff }
  176. writeln('Voorbeeld programma in ‚‚n dimensie, voor domein [0..1]');
  177. writeln;
  178. t := 0.5;
  179. roofnr(@JdeJongEx, 1, t, residu, 1e-6, term);
  180. if term = 1 then
  181. writeln(' Norm van de residuen', residu: 20, #13#10,
  182. ' Berekende oplossing')
  183. else
  184. writeln(' Proces afgebroken term = ', term, #13#10,
  185. ' Laatst berekende waarden');
  186. writeln;
  187. Writeln(' ', t: 20);
  188. end.
  189. program Roofnrte;
  190. uses
  191. typ,
  192. roo;
  193. type
  194. maxarray = array[1..128] of ArbFloat;
  195. var
  196. n: ArbInt;
  197. a: ArbFloat;
  198. ah2: ArbFloat;
  199. procedure PraktikumEx(var x, fx: ArbFloat; var deff: boolean);
  200. var
  201. xloc: maxarray absolute x;
  202. floc: maxarray absolute fx;
  203. i: ArbInt;
  204. begin
  205. floc[1] := 2 * (xloc[1] - xloc[2]) - ah2 * exp(xloc[1]);
  206. for i := 2 to n - 1 do
  207. floc[i] := -xloc[i - 1] + 2 * xloc[i] - xloc[i + 1] - ah2 * exp(xloc[i]);
  208. floc[n] := -xloc[n - 1] + 2 * xloc[n] - ah2 * exp(xloc[n]);
  209. end;
  210. const
  211. m = 9;
  212. procedure NagExample(var x, fx: ArbFloat; var deff: boolean);
  213. var
  214. xloc: array[1..m] of ArbFloat absolute x;
  215. floc: array[1..m] of ArbFloat absolute fx;
  216. k: ArbInt;
  217. begin
  218. floc[1] := 1 + (3 - 2 * xloc[1]) * xloc[1] - 2 * xloc[2];
  219. for k := 2 to m - 1 do
  220. floc[k] := 1 + (3 - 2 * xloc[k]) * xloc[k] - xloc[k - 1] - 2 * xloc[k + 1];
  221. floc[m] := 1 + (3 - 2 * xloc[m]) * xloc[m] - xloc[m - 1];
  222. end;
  223. procedure MatlabEx(var x, fx: ArbFloat; var deff: boolean);
  224. var
  225. xloc: array[1..3] of ArbFloat absolute x;
  226. floc: array[1..3] of ArbFloat absolute fx;
  227. begin
  228. floc[1] := sin(xloc[1]) + sqr(xloc[2]) + ln(xloc[3]) - 7;
  229. floc[2] := 3 * xloc[1] + exp(xloc[2] * ln(2)) - xloc[3] * sqr(xloc[3]) + 1;
  230. floc[3] := xloc[1] + xloc[2] + xloc[3] - 5;
  231. end;
  232. procedure TPNumlibEx(var x, fx: ArbFloat; var deff: boolean);
  233. begin
  234. fx := cos(x);
  235. end;
  236. procedure JdeJongEx(var x, fx: ArbFloat; var deff: boolean);
  237. begin
  238. if (x >= 0) and (x <= 1) then
  239. fx := x - 2
  240. else
  241. deff := False;
  242. end;
  243. procedure Uitvoer(var x1: ArbFloat; n, step: ArbInt);
  244. var
  245. i: ArbInt;
  246. xloc: maxarray absolute x1;
  247. begin
  248. i := 1;
  249. while (i <= n) do
  250. begin
  251. writeln(i: 5, ' ', xloc[i]: 20);
  252. Inc(i, step);
  253. end;
  254. writeln;
  255. end;
  256. var
  257. x: ^maxarray;
  258. t, residu: ArbFloat;
  259. i, term: ArbInt;
  260. begin
  261. { praktikum sommetje }
  262. n := 8;
  263. a := 0.50;
  264. repeat
  265. ah2 := a / sqr(n);
  266. GetMem(x, n * SizeOf(ArbFloat));
  267. for i := 1 to n do
  268. x^[i] := 0;
  269. writeln('Voorbeeld programma ''praktikum'', resultaten voor n= ', n: 2);
  270. writeln;
  271. roofnr(@PraktikumEx, n, x^[1], residu, 1e-4, term);
  272. if term = 1 then
  273. writeln(' Norm van de residuen', residu: 20, #13#10,
  274. ' Berekende oplossing')
  275. else
  276. writeln(' Proces afgebroken term = ', term, #13#10,
  277. ' Laatst berekende waarden');
  278. writeln;
  279. Uitvoer(x^[1], n, n div 8);
  280. FreeMem(x, n * SizeOf(ArbFloat));
  281. n := n * 2
  282. until n = 128;
  283. { Nag procedure bibliotheek voorbeeld }
  284. GetMem(x, m * SizeOf(ArbFloat));
  285. for i := 1 to m do
  286. x^[i] := -1;
  287. writeln('Voorbeeld programma ''NAG-bibliotheek'' met m= ', m: 2);
  288. writeln;
  289. roofnr(@NagExample, m, x^[1], residu, 1e-6, term);
  290. if term = 1 then
  291. writeln(' Norm van de residuen', residu: 20, #13#10,
  292. ' Berekende oplossing')
  293. else
  294. writeln(' Proces afgebroken term = ', term, #13#10,
  295. ' Laatst berekende waarden');
  296. writeln;
  297. Uitvoer(x^[1], m, 1);
  298. FreeMem(x, m * SizeOf(ArbFloat));
  299. { Matlab voorbeeld uit handleiding }
  300. n := 3;
  301. GetMem(x, n * SizeOf(ArbFloat));
  302. for i := 1 to n do
  303. x^[i] := 1;
  304. writeln('Voorbeeld programma ''MATLAB handleiding'', resultaten voor n= ', n: 2);
  305. writeln;
  306. roofnr(@MatlabEx, n, x^[1], residu, 1e-6, term);
  307. if term = 1 then
  308. writeln(' Norm van de residuen', residu: 20, #13#10,
  309. ' Berekende oplossing')
  310. else
  311. writeln(' Proces afgebroken term = ', term, #13#10,
  312. ' Laatst berekende waarden');
  313. writeln;
  314. Uitvoer(x^[1], n, 1);
  315. FreeMem(x, n * SizeOf(ArbFloat));
  316. { 1-dimensionaal voorbeeld uit TPNumlib }
  317. writeln('Voorbeeld programma ''TPNumlib'' voor ‚‚n dimensie');
  318. writeln;
  319. t := 1;
  320. roofnr(@TPNumlibEx, 1, t, residu, 1e-6, term);
  321. if term = 1 then
  322. writeln(' Norm van de residuen', residu: 20, #13#10,
  323. ' Berekende oplossing')
  324. else
  325. writeln(' Proces afgebroken term = ', term, #13#10,
  326. ' Laatst berekende waarden');
  327. writeln;
  328. Writeln(' ', t: 20);
  329. { Matlab voorbeeld uit handleiding }
  330. { dit moet fout gaan }
  331. n := 3;
  332. GetMem(x, n * SizeOf(ArbFloat));
  333. for i := 1 to n do
  334. x^[i] := 1;
  335. writeln;
  336. writeln('Voorbeeld programma ''MATLAB handleiding'', resultaten voor n= ', n: 2);
  337. writeln('Gaat niet goed want de relatieve fout is gelijk aan 0 gekozen');
  338. writeln;
  339. roofnr(@MatlabEx, n, x^[1], residu, 0, term);
  340. if term = 1 then
  341. writeln(' Norm van de residuen', residu: 20, #13#10,
  342. ' Berekende oplossing')
  343. else
  344. writeln(' Proces afgebroken term = ', term, #13#10,
  345. ' Laatst berekende waarden');
  346. writeln;
  347. Uitvoer(x^[1], n, 1);
  348. writeln;
  349. writeln('Voorbeeld programma ''MATLAB handleiding'', resultaten voor n= ', n: 2);
  350. writeln;
  351. for i := 1 to n do
  352. x^[i] := 1;
  353. roofnr(@MatlabEx, n, x^[1], residu, 1e-8, term);
  354. if term = 1 then
  355. writeln(' Norm van de residuen', residu: 20, #13#10,
  356. ' Berekende oplossing')
  357. else
  358. writeln(' Proces afgebroken term = ', term, #13#10,
  359. ' Laatst berekende waarden');
  360. writeln;
  361. Uitvoer(x^[1], n, 1);
  362. FreeMem(x, n * SizeOf(ArbFloat));
  363. { 1-dimensionaal voorbeeld voor deff }
  364. writeln('Voorbeeld programma in ‚‚n dimensie, voor domein [0..1]');
  365. writeln;
  366. t := 0.5;
  367. roofnr(@JdeJongEx, 1, t, residu, 1e-6, term);
  368. if term = 1 then
  369. writeln(' Norm van de residuen', residu: 20, #13#10,
  370. ' Berekende oplossing')
  371. else
  372. writeln(' Proces afgebroken term = ', term, #13#10,
  373. ' Laatst berekende waarden');
  374. writeln;
  375. Writeln(' ', t: 20);
  376. end.