inv.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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
  53. that is independent of the exact real type. (Contrary to directly
  54. specifying single, real, double or extended in library and
  55. examples). Typ.pas and the central includefile have some conditional
  56. code to switch between floating point 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
  65. dimensional matrix containing the matrix elements in a square
  66. partial block.
  67. \DeclarationandParams
  68. \lstinline|procedure invgen(n, rwidth: ArbInt; var ai: ArbFloat;var term: ArbInt);|
  69. \begin{description}
  70. \item[n: integer] \mbox{ } \\
  71. The parameter {\bf n} describes the size of the matrix
  72. \item[rwidth: integer] \mbox{} \\
  73. The parameter {\bf rwidth} describes the declared rowlength of the two dimensional
  74. matrix.
  75. \item[var ai: real] \mbox{} \\
  76. The parameter {\bf ai} must contain to the two dimensional array element
  77. that is top-left in the matrix.
  78. After the function has ended successfully (\textbf{term=1}) then
  79. the input matrix has been changed into its inverse, otherwise the contents
  80. of the input matrix are undefined.
  81. \item[var term: integer] \mbox{} \\
  82. After the procedure has run, this variable contains the reason for
  83. the termination of the procedure:\\
  84. {\bf term}=1, successful termination, the inverse has been calculated
  85. {\bf term}=2, inverse matrix could not be calculated because the matrix
  86. is (very close to) being singular.
  87. {\bf term}=3, wrong input n$<$1
  88. \end{description}
  89. \Remarks
  90. This procedure does not do array range checks. When called with invalid
  91. parameters, invalid/nonsense responses or even crashes may be the result.
  92. \Example
  93. Calculate the inverse of
  94. \[
  95. A=
  96. \left(
  97. \begin{array}{rrrr}
  98. 4 & 2 & 4 & 1 \\
  99. 30 & 20 & 45 & 12 \\
  100. 20 & 15 & 36 & 10 \\
  101. 35 & 28 & 70 & 20
  102. \end{array}
  103. \right)
  104. .
  105. \]
  106. Below is the source of the invgenex demo that demonstrates invgenex,
  107. some routines of iom were used to construct matrices.
  108. \NUMLIBexample{invgenex}
  109. \ProgramData
  110. The input datafile looks like:
  111. \begin{verbatim}
  112. 4 2 4 1
  113. 30 20 45 12
  114. 20 15 36 10
  115. 35 28 70 20
  116. \end{verbatim}
  117. \ProgramResults
  118. \begin{verbatim}
  119. program results invgenex
  120. A =
  121. 4.0000000000000000E+0000 2.0000000000000000E+0000
  122. 3.0000000000000000E+0001 2.0000000000000000E+0001
  123. 2.0000000000000000E+0001 1.5000000000000000E+0001
  124. 3.5000000000000000E+0001 2.8000000000000000E+0001
  125. 4.0000000000000000E+0000 1.0000000000000000E+0000
  126. 4.5000000000000000E+0001 1.2000000000000000E+0001
  127. 3.6000000000000000E+0001 1.0000000000000000E+0001
  128. 7.0000000000000000E+0001 2.0000000000000000E+0001
  129. term= 1
  130. inverse of A =
  131. 4.0000000000000000E+0000 -2.0000000000000000E+0000
  132. -3.0000000000000000E+0001 2.0000000000000000E+0001
  133. 2.0000000000000000E+0001 -1.5000000000000000E+0001
  134. -3.4999999999999999E+0001 2.7999999999999999E+0001
  135. 3.9999999999999999E+0000 -1.0000000000000000E+0000
  136. -4.4999999999999999E+0001 1.2000000000000000E+0001
  137. 3.5999999999999999E+0001 -1.0000000000000000E+0001
  138. -6.9999999999999999E+0001 2.0000000000000000E+0001
  139. \end{verbatim}
  140. \Precision
  141. The procedure doesn't supply information about the precision of the
  142. operation after termination.
  143. \Method
  144. The calculation of the inverse is based on LU decomposition with partial
  145. pivoting.
  146. \References
  147. Wilkinson, J.H. and Reinsch, C.\\
  148. Handbook for Automatic Computation.\\
  149. Volume II, Linear Algebra.\\
  150. Springer Verlag, Contribution I/7, 1971.
  151. \end{procedure}
  152. \begin{procedure}{invgpd}
  153. \FunctionDescription
  154. Procedure to calculate the inverse of a symmetrical, positive
  155. definitive matrix
  156. \Dataorganisation The procedure assumes that the calling program has
  157. declared a two dimensional matrix containing the matrix elements in
  158. 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 row length of the two dimensional
  166. matrix.
  167. \item[var ai: real] \mbox{} \\
  168. The parameter {\bf ai} must contain to the two dimensional array element
  169. that is top-left in the matrix.
  170. After the function has ended successfully (\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, successful 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 bottom left 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
  237. for a symmetrical positive definitive 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 matrix elements in (the bottom
  248. left part 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 row length of the two dimensional
  256. matrix.
  257. \item[var ai: real] \mbox{} \\
  258. The parameter {\bf ai} must contain to the two dimensional array element
  259. that is top-left in the matrix.
  260. After the function has ended successfully (\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, successful 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 bottom left 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. Calculating the inverse of
  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}