inv.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. %
  2. % part of numlib docs. In time this won't be a standalone pdf anymore, but part of a larger part.
  3. % for now I keep it directly compliable. Uses fpc.sty from fpc-docs pkg.
  4. %
  5. \documentclass{report}
  6. \usepackage{fpc}
  7. \lstset{%
  8. basicstyle=\small,
  9. language=delphi,
  10. commentstyle=\itshape,
  11. keywordstyle=\bfseries,
  12. showstringspaces=false,
  13. frame=
  14. }
  15. \makeindex
  16. \newcommand{\FunctionDescription}{\item[Description]\rmfamily}
  17. \newcommand{\Dataorganisation}{\item[Data Struct]\rmfamily}
  18. \newcommand{\DeclarationandParams}{\item[Declaration]\rmfamily}
  19. \newcommand{\References}{\item[References]\rmfamily}
  20. \newcommand{\Method}{\item[Method]\rmfamily}
  21. \newcommand{\Precision}{\item[Precision]\rmfamily}
  22. \newcommand{\Remarks}{\item[Remarks]\rmfamily}
  23. \newcommand{\Example}{\item[Example]\rmfamily}
  24. \newcommand{\ProgramData}{\item[Example Data]\rmfamily}
  25. \newcommand{\ProgramResults}{\item[Example Result]\rmfamily}
  26. \makeatletter
  27. \@ifpackageloaded{tex4ht}{%
  28. \newcommand{\NUMLIBexample}[1]{
  29. \par \file{\textbf{Listing:} \exampledir/#1.pas}%
  30. \HCode{<HR/>}%
  31. \listinginput[9999]{5000}{\exampledir/#1.pas}%
  32. \HCode{<HR/>}%
  33. }%
  34. }{% else ifpackageloaded
  35. \newcommand{\NUMLIBexample}[1]{%
  36. \par \file{\textbf{Listing:} \exampledir/#1.pas}%
  37. \lstinputlisting{\exampledir/#1.pas}%
  38. }% End of FPCExample
  39. }% End of ifpackageloaded.
  40. \makeatother
  41. %
  42. \begin{document}
  43. \FPCexampledir{../examples}
  44. \section{general comments}
  45. \textbf{Original comments:} \\
  46. The used floating point type \textbf{real} depends on the used version,
  47. see the general introduction for more information. You'll need to USE
  48. units typ an inv to use these routines.
  49. \textbf{MvdV notes:} \\
  50. Integers used for parameters are of type "ArbInt" to avoid problems with
  51. systems that define integer differently depending on mode.
  52. Floating point values are of type "ArbFloat" to allow writing code that is
  53. independant of the exact real type. (Contrary to directly specifying single,
  54. real, double or extended in library and examples). Typ.pas and the central
  55. includefile have some conditional code to switch between floating point
  56. types.
  57. These changes were already prepared somewhat when I got the lib, but weren't
  58. consequently applied. I did that while porting to FPC.
  59. \section{Unit inv}
  60. \begin{procedure}{invgen}
  61. \FunctionDescription
  62. Procedure to calculate the inverse of a matrix.
  63. \Dataorganisation
  64. The procedure assumes that the calling program has declared a two dimensional
  65. matrix containing the maxtrixelements in a square partial block.
  66. \DeclarationandParams
  67. \lstinline|procedure invgen(n, rwidth: ArbInt; var ai: ArbFloat;var term: ArbInt);|
  68. \begin{description}
  69. \item[n: integer] \mbox{ } \\
  70. The parameter {\bf n} describes the size of the matrix
  71. \item[rwidth: integer] \mbox{} \\
  72. The parameter {\bf rwidth} describes the declared rowlength of the twodimensional
  73. matrix.
  74. \item[var ai: real] \mbox{} \\
  75. The parameter {\bf ai} must contain to the twodimensional arrayelement
  76. that is top-left in the matrix.
  77. After the function has ended succesfully (\textbf{term=1}) then
  78. the input matrix has been changed into its inverse, otherwise the contents
  79. of the input matrix are undefined.
  80. \item[var term: integer] \mbox{} \\
  81. After the procedure has run, this variable contains the reason for
  82. the termination of the procedure:\\
  83. {\bf term}=1, succesfull termination, the inverse has been calculated
  84. {\bf term}=2, inverse matrix could not be calculated because the matrix
  85. is (very close to) being singular.
  86. {\bf term}=3, wrong input n$<$1
  87. \end{description}
  88. \Remarks
  89. This procedure does not do array range checks. When called with invalid
  90. parameters, invalid/nonsense responses or even crashes may be the result.
  91. \Example
  92. Calculate the inverse of
  93. \[
  94. A=
  95. \left(
  96. \begin{array}{rrrr}
  97. 4 & 2 & 4 & 1 \\
  98. 30 & 20 & 45 & 12 \\
  99. 20 & 15 & 36 & 10 \\
  100. 35 & 28 & 70 & 20
  101. \end{array}
  102. \right)
  103. .
  104. \]
  105. Below is the source of the invgenex demo that demontrates invgenex, some
  106. routines of iom were used to construct matrices.
  107. \NUMLIBexample{invgenex}
  108. \ProgramData
  109. The input datafile looks like:
  110. \begin{verbatim}
  111. 4 2 4 1
  112. 30 20 45 12
  113. 20 15 36 10
  114. 35 28 70 20
  115. \end{verbatim}
  116. \ProgramResults
  117. \begin{verbatim}
  118. program results invgenex
  119. A =
  120. 4.0000000000000000E+0000 2.0000000000000000E+0000
  121. 3.0000000000000000E+0001 2.0000000000000000E+0001
  122. 2.0000000000000000E+0001 1.5000000000000000E+0001
  123. 3.5000000000000000E+0001 2.8000000000000000E+0001
  124. 4.0000000000000000E+0000 1.0000000000000000E+0000
  125. 4.5000000000000000E+0001 1.2000000000000000E+0001
  126. 3.6000000000000000E+0001 1.0000000000000000E+0001
  127. 7.0000000000000000E+0001 2.0000000000000000E+0001
  128. term= 1
  129. inverse of A =
  130. 4.0000000000000000E+0000 -2.0000000000000000E+0000
  131. -3.0000000000000000E+0001 2.0000000000000000E+0001
  132. 2.0000000000000000E+0001 -1.5000000000000000E+0001
  133. -3.4999999999999999E+0001 2.7999999999999999E+0001
  134. 3.9999999999999999E+0000 -1.0000000000000000E+0000
  135. -4.4999999999999999E+0001 1.2000000000000000E+0001
  136. 3.5999999999999999E+0001 -1.0000000000000000E+0001
  137. -6.9999999999999999E+0001 2.0000000000000000E+0001
  138. \end{verbatim}
  139. \Precision
  140. The procedure doesn't supply information about the precision of the
  141. operation after termination.
  142. \Method
  143. The calculation of the inverse is based on LU decomposition with partial
  144. pivoting.
  145. \References
  146. Wilkinson, J.H. and Reinsch, C.\\
  147. Handbook for Automatic Computation.\\
  148. Volume II, Linear Algebra.\\
  149. Springer Verlag, Contribution I/7, 1971.
  150. \end{procedure}
  151. \begin{procedure}{invgpd}
  152. \FunctionDescription
  153. Procedure to calculate the inverse of a symmetrical, positive definite
  154. matrix
  155. %van een symmetrische,positief definiete matrix.
  156. \Dataorganisation
  157. The procedure assumes that the calling program has declared a two dimensional
  158. matrix containing the maxtrixelements in a square partial block.
  159. \DeclarationandParams
  160. \lstinline|procedure invgpd(n, rwidth: ArbInt; var ai: ArbFloat; var term: ArbInt);|
  161. \begin{description}
  162. \item[n: integer] \mbox{ } \\
  163. The parameter {\bf n} describes the size of the matrix
  164. \item[rwidth: integer] \mbox{} \\
  165. The parameter {\bf rwidth} describes the declared rowlength of the twodimensional
  166. matrix.
  167. \item[var ai: real] \mbox{} \\
  168. The parameter {\bf ai} must contain to the twodimensional arrayelement
  169. that is top-left in the matrix.
  170. After the function has ended succesfully (\textbf{term=1}) then
  171. the input matrix has been changed into its inverse, otherwise the contents
  172. of the input matrix are undefined.
  173. \item[var term: integer] \mbox{} \\
  174. After the procedure has run, this variable contains the reason for
  175. the termination of the procedure:\\
  176. {\bf term}=1, succesfull termination, the inverse has been calculated
  177. {\bf term}=2, inverse matrix could not be calculated because the matrix
  178. is (very close to) being singular.
  179. {\bf term}=3, wrong input n$<$1
  180. \end{description}
  181. \Remarks
  182. \begin{itemize}
  183. \item Only the bottomleft part of the matrix $A$ needs to be passed.
  184. \item \textbf{Warning} This procedure does not do array range checks. When called with invalid
  185. parameters, invalid/nonsense responses or even crashes may be the result.
  186. \end{itemize}
  187. \Example
  188. Calculate the inverse of
  189. \[
  190. A=
  191. \left(
  192. \begin{array}{rrrr}
  193. 5 & 7 & 6 & 5 \\
  194. 7 & 10 & 8 & 7 \\
  195. 6 & 8 & 10 & 9 \\
  196. 5 & 7 & 9 & 10
  197. \end{array}
  198. \right)
  199. .
  200. \]
  201. \NUMLIBexample{invgpdex}
  202. \ProgramData
  203. \begin{verbatim}
  204. 5
  205. 7 10
  206. 6 8 10
  207. 5 7 9 10
  208. \end{verbatim}
  209. \ProgramResults
  210. \begin{verbatim}
  211. program results invgpdex
  212. A =
  213. 5.0000000000000000E+0000 7.0000000000000000E+0000
  214. 7.0000000000000000E+0000 1.0000000000000000E+0001
  215. 6.0000000000000000E+0000 8.0000000000000000E+0000
  216. 5.0000000000000000E+0000 7.0000000000000000E+0000
  217. 6.0000000000000000E+0000 5.0000000000000000E+0000
  218. 8.0000000000000000E+0000 7.0000000000000000E+0000
  219. 1.0000000000000000E+0001 9.0000000000000000E+0000
  220. 9.0000000000000000E+0000 1.0000000000000000E+0001
  221. term= 1
  222. inverse of A =
  223. 6.8000000000000000E+0001 -4.1000000000000000E+0001
  224. -4.1000000000000000E+0001 2.5000000000000000E+0001
  225. -1.7000000000000000E+0001 1.0000000000000000E+0001
  226. 1.0000000000000000E+0001 -6.0000000000000000E+0000
  227. -1.7000000000000000E+0001 1.0000000000000000E+0001
  228. 1.0000000000000000E+0001 -6.0000000000000000E+0000
  229. 5.0000000000000000E+0000 -3.0000000000000000E+0000
  230. -3.0000000000000000E+0000 2.0000000000000000E+0000
  231. \end{verbatim}
  232. \Precision
  233. The procedure doesn't supply information about the precision of the
  234. operation after termination.
  235. \Method
  236. The calculation of the inverse is based on Cholesky decomposition for a
  237. symmetrical positive definitie matrix.
  238. \References
  239. Wilkinson, J.H. and Reinsch, C.\\ Handbook for Automatic Computation.\\
  240. Volume II, Linear Algebra.\\ Springer Verlag, Contribution I/7, 1971.
  241. \end{procedure}
  242. \begin{procedure}{invgsy}
  243. \FunctionDescription
  244. Procedure to calculate the inverse of a symmetrical matrix.
  245. \Dataorganisation
  246. The procedure assumes that the calling program has declared a two
  247. dimensional matrix containing the maxtrixelements in (the bottomleft part
  248. of) a square partial block.
  249. \DeclarationandParams
  250. \lstinline|procedure invgsy(n, rwidth: ArbInt; var ai: ArbFloat;var term:ArbInt);|
  251. \begin{description}
  252. \item[n: integer] \mbox{ } \\
  253. The parameter {\bf n} describes the size of the matrix
  254. \item[rwidth: integer] \mbox{} \\
  255. The parameter {\bf rwidth} describes the declared rowlength of the twodimensional
  256. matrix.
  257. \item[var ai: real] \mbox{} \\
  258. The parameter {\bf ai} must contain to the twodimensional arrayelement
  259. that is top-left in the matrix.
  260. After the function has ended succesfully (\textbf{term=1}) then
  261. the input matrix has been changed into its inverse, otherwise the contents
  262. of the input matrix are undefined.
  263. \item[var term: integer] \mbox{} \\
  264. After the procedure has run, this variable contains the reason for
  265. the termination of the procedure:\\
  266. {\bf term}=1, succesfull termination, the inverse has been calculated
  267. {\bf term}=2, inverse matrix could not be calculated because the matrix
  268. is (very close to) being singular.
  269. {\bf term}=3, wrong input n$<$1
  270. \end{description}
  271. \Remarks
  272. \begin{itemize}
  273. \item Only the bottomleft part of the matrix $A$ needs to be passed.
  274. \item \textbf{Warning} This procedure does not do array range checks. When called with invalid
  275. parameters, invalid/nonsense responses or even crashes may be the result.
  276. \end{itemize}
  277. \Example
  278. Het berekenen van de inverse van
  279. \[
  280. A=
  281. \left(
  282. \begin{array}{rrrr}
  283. 5 & 7 & 6 & 5 \\
  284. 7 & 10 & 8 & 7 \\
  285. 6 & 8 & 10 & 9 \\
  286. 5 & 7 & 9 & 10
  287. \end{array}
  288. \right)
  289. .
  290. \]
  291. \NUMLIBexample{invgsyex}
  292. \ProgramData
  293. \begin{verbatim}
  294. 5
  295. 7 10
  296. 6 8 10
  297. 5 7 9 10
  298. \end{verbatim}
  299. \ProgramResults
  300. \begin{verbatim}
  301. program results invgsyex
  302. A =
  303. 5.0000000000000000E+0000 7.0000000000000000E+0000
  304. 7.0000000000000000E+0000 1.0000000000000000E+0001
  305. 6.0000000000000000E+0000 8.0000000000000000E+0000
  306. 5.0000000000000000E+0000 7.0000000000000000E+0000
  307. 6.0000000000000000E+0000 5.0000000000000000E+0000
  308. 8.0000000000000000E+0000 7.0000000000000000E+0000
  309. 1.0000000000000000E+0001 9.0000000000000000E+0000
  310. 9.0000000000000000E+0000 1.0000000000000000E+0001
  311. term= 1
  312. inverse of A =
  313. 6.8000000000000001E+0001 -4.1000000000000001E+0001
  314. -4.1000000000000001E+0001 2.5000000000000000E+0001
  315. -1.7000000000000000E+0001 1.0000000000000000E+0001
  316. 1.0000000000000000E+0001 -6.0000000000000001E+0000
  317. -1.7000000000000000E+0001 1.0000000000000000E+0001
  318. 1.0000000000000000E+0001 -6.0000000000000001E+0000
  319. 5.0000000000000001E+0000 -3.0000000000000000E+0000
  320. -3.0000000000000000E+0000 2.0000000000000000E+0000
  321. \end{verbatim}
  322. \Precision
  323. The procedure doesn't supply information about the precision of the
  324. operation after termination.
  325. \Method
  326. The calculation of the inverse is based on reduction of a symmetrical
  327. matrix to a tridiagonal form.
  328. \References
  329. Aasen, J. O. \\
  330. On the reduction of a symmetric matrix to tridiagonal form. \\
  331. BIT, 11, (1971), pag. 223-242.
  332. \end{procedure}
  333. \end{document}