123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- %
- % part of numlib docs. In time this won't be a standalone pdf anymore, but part of a larger part.
- % for now I keep it directly compliable. Uses fpc.sty from fpc-docs pkg.
- %
- \documentclass{report}
- \usepackage{fpc}
- \lstset{%
- basicstyle=\small,
- language=delphi,
- commentstyle=\itshape,
- keywordstyle=\bfseries,
- showstringspaces=false,
- frame=
- }
- \makeindex
- \newcommand{\FunctionDescription}{\item[Description]\rmfamily}
- \newcommand{\Dataorganisation}{\item[Data Struct]\rmfamily}
- \newcommand{\DeclarationandParams}{\item[Declaration]\rmfamily}
- \newcommand{\References}{\item[References]\rmfamily}
- \newcommand{\Method}{\item[Method]\rmfamily}
- \newcommand{\Precision}{\item[Precision]\rmfamily}
- \newcommand{\Remarks}{\item[Remarks]\rmfamily}
- \newcommand{\Example}{\item[Example]\rmfamily}
- \newcommand{\ProgramData}{\item[Example Data]\rmfamily}
- \newcommand{\ProgramResults}{\item[Example Result]\rmfamily}
- \begin{document}
- \section{Unit inv}
- \textbf{Original comments:} \\
- The used floating point type \textbf{real} depends on the used version,
- see the general introduction for more information. You'll need to USE
- units typ an inv to use these routines.
- \textbf{MvdV notes:} \\
- Integers used for parameters are of type "ArbInt" to avoid problems with
- systems that define integer differently depending on mode.
- Floating point values are of type "ArbFloat" to allow writing code that is
- independant of the exact real type. (Contrary to directly specifying single,
- real, double or extended in library and examples). Typ.pas and the central
- includefile have some conditional code to switch between floating point
- types.
- These changes were already prepared somewhat when I got the lib, but weren't
- consequently applied. I did that while porting to FPC.
- \begin{procedure}{invgen}
- \FunctionDescription
- Procedure to calculate the inverse of a matrix.
- \Dataorganisation
- The procedure assumes that the calling program has declared a two dimensional
- matrix containing the maxtrixelements in a square partial block.
- \DeclarationandParams
- \lstinline|procedure invgen(n, rwidth: ArbInt; var ai: ArbFloat;var term: ArbInt);|
- \begin{description}
- \item[n: integer] \mbox{ } \\
- The parameter {\bf n} describes the size of the matrix
- \item[rwidth: integer] \mbox{} \\
- The parameter {\bf rwidth} describes the declared rowlength of the twodimensional
- matrix.
- \item[var ai: real] \mbox{} \\
- The parameter {\bf ai} must contain to the twodimensional arrayelement
- that is top-left in the matrix.
- After the function has ended succesfully (\textbf{term=1}) then
- the input matrix has been changed into its inverse, otherwise the contents
- of the input matrix are undefined.
- ongedefinieerd.
- \item[var term: integer] \mbox{} \\
- After the procedure has run, this variable contains the reason for
- the termination of the procedure:\\
- {\bf term}=1, succesfull termination, the inverse has been calculated
- {\bf term}=2, inverse matrix could not be calculated because the matrix
- is (very close to) being singular.
- {\bf term}=3, wrong input n$<$1
- \end{description}
- \Remarks
- This procedure does not do array range checks. When called with invalid
- parameters, invalid/nonsense responses or even crashes may be the result.
- \Example
- Calculate the inverse of
- \[
- A=
- \left(
- \begin{array}{rrrr}
- 4 & 2 & 4 & 1 \\
- 30 & 20 & 45 & 12 \\
- 20 & 15 & 36 & 10 \\
- 35 & 28 & 70 & 20
- \end{array}
- \right)
- .
- \]
- Below is the source of the invgenex demo that demontrates invgenex, some
- routines of iom were used to construct matrices.
- \begin{lstlisting}
- program invgenex;
- uses typ, iom, inv;
- const n = 4;
- var term : ArbInt;
- A : array[1..n,1..n] of ArbFloat;
- begin
- assign(input, paramstr(1)); reset(input);
- assign(output, paramstr(2)); rewrite(output);
- writeln('program results invgenex');
- { Read matrix A }
- iomrem(input, A[1,1], n, n, n);
- { Print matrix A }
- writeln; writeln('A =');
- iomwrm(output, A[1,1], n, n, n, numdig);
- { Calculation of the inverse of A }
- invgen(n, n, A[1,1], term);
- writeln; writeln('term=', term:2);
- if term=1 then
- { print inverse inverse of A }
- begin
- writeln; writeln('inverse of A =');
- iomwrm(output, A[1,1], n, n, n, numdig);
- end; {term=1}
- close(input); close(output)
- end.
- \end{lstlisting}
- \ProgramData
- The input datafile looks like:
- \begin{verbatim}
- 4 2 4 1
- 30 20 45 12
- 20 15 36 10
- 35 28 70 20
- \end{verbatim}
- \ProgramResults
- \begin{verbatim}
- program results invgenex
- A =
- 4.0000000000000000E+0000 2.0000000000000000E+0000
- 3.0000000000000000E+0001 2.0000000000000000E+0001
- 2.0000000000000000E+0001 1.5000000000000000E+0001
- 3.5000000000000000E+0001 2.8000000000000000E+0001
- 4.0000000000000000E+0000 1.0000000000000000E+0000
- 4.5000000000000000E+0001 1.2000000000000000E+0001
- 3.6000000000000000E+0001 1.0000000000000000E+0001
- 7.0000000000000000E+0001 2.0000000000000000E+0001
- term= 1
- inverse of A =
- 4.0000000000000000E+0000 -2.0000000000000000E+0000
- -3.0000000000000000E+0001 2.0000000000000000E+0001
- 2.0000000000000000E+0001 -1.5000000000000000E+0001
- -3.4999999999999999E+0001 2.7999999999999999E+0001
- 3.9999999999999999E+0000 -1.0000000000000000E+0000
- -4.4999999999999999E+0001 1.2000000000000000E+0001
- 3.5999999999999999E+0001 -1.0000000000000000E+0001
- -6.9999999999999999E+0001 2.0000000000000000E+0001
- \end{verbatim}
- \Precision
- The procedure doesn't supply information about the precision of the
- operation after termination.
- \Method
- The calculation of the inverse is based on LU decomposition with partial
- pivoting.
- \References
- Wilkinson, J.H. and Reinsch, C.\\
- Handbook for Automatic Computation.\\
- Volume II, Linear Algebra.\\
- Springer Verlag, Contribution I/7, 1971.
- \end{procedure}
- \begin{procedure}{invgpd}
- \FunctionDescription
- Procedure to calculate the inverse of a symmetrical, postivive definite
- %van een symmetrische,positief definiete matrix.
- \Dataorganisation
- The procedure assumes that the calling program has declared a two dimensional
- matrix containing the maxtrixelements in a square partial block.
- \DeclarationandParams
- \lstinline|procedure invgpd(n, rwidth: ArbInt; var ai: ArbFloat; var term: ArbInt);|
- \begin{description}
- \item[n: integer] \mbox{ } \\
- The parameter {\bf n} describes the size of the matrix
- \item[rwidth: integer] \mbox{} \\
- The parameter {\bf rwidth} describes the declared rowlength of the twodimensional
- matrix.
- \item[var ai: real] \mbox{} \\
- The parameter {\bf ai} must contain to the twodimensional arrayelement
- that is top-left in the matrix.
- After the function has ended succesfully (\textbf{term=1}) then
- the input matrix has been changed into its inverse, otherwise the contents
- of the input matrix are undefined.
- ongedefinieerd.
- \item[var term: integer] \mbox{} \\
- After the procedure has run, this variable contains the reason for
- the termination of the procedure:\\
- {\bf term}=1, succesfull termination, the inverse has been calculated
- {\bf term}=2, inverse matrix could not be calculated because the matrix
- is (very close to) being singular.
- {\bf term}=3, wrong input n$<$1
- \end{description}
- \Remarks
- \begin{itemize}
- \item Only the bottomleft part of the matrix $A$ needs to be passed.
- \item \textbf{Warning} This procedure does not do array range checks. When called with invalid
- parameters, invalid/nonsense responses or even crashes may be the result.
- \end{itemize}
- \Example
- Calculate the inverse of
- \[
- A=
- \left(
- \begin{array}{rrrr}
- 5 & 7 & 6 & 5 \\
- 7 & 10 & 8 & 7 \\
- 6 & 8 & 10 & 9 \\
- 5 & 7 & 9 & 10
- \end{array}
- \right)
- .
- \]
- \begin{lstlisting}
- program invgpdex;
- uses typ, iom, inv;
- const n = 4;
- var i, j, term : ArbInt;
- A : array[1..n,1..n] of ArbFloat;
- begin
- assign(input, paramstr(1)); reset(input);
- assign(output, paramstr(2)); rewrite(output);
- writeln('program results invgpdex');
- { Read bottom leftpart of matrix A}
- for i:=1 to n do iomrev(input, A[i,1], i);
- { print matrix A }
- writeln; writeln('A =');
- for i:=1 to n do for j:=1 to i-1 do A[j,i]:=A[i,j];
- iomwrm(output, A[1,1], n, n, n, numdig);
- { Calculate inverse of matrix A}
- invgpd(n, n, A[1,1], term);
- writeln; writeln('term=', term:2);
- if term=1 then
- { Print inverse of matrix A}
- begin
- writeln; writeln('inverse of A =');
- iomwrm(output, A[1,1], n, n, n, numdig);
- end; {term=1}
- close(input); close(output)
- end.
- \end{lstlisting}
- \ProgramData
- \begin{verbatim}
- 5
- 7 10
- 6 8 10
- 5 7 9 10
- \end{verbatim}
- \ProgramResults
- \begin{verbatim}
- program results invgpdex
- A =
- 5.0000000000000000E+0000 7.0000000000000000E+0000
- 7.0000000000000000E+0000 1.0000000000000000E+0001
- 6.0000000000000000E+0000 8.0000000000000000E+0000
- 5.0000000000000000E+0000 7.0000000000000000E+0000
- 6.0000000000000000E+0000 5.0000000000000000E+0000
- 8.0000000000000000E+0000 7.0000000000000000E+0000
- 1.0000000000000000E+0001 9.0000000000000000E+0000
- 9.0000000000000000E+0000 1.0000000000000000E+0001
- term= 1
- inverse of A =
- 6.8000000000000000E+0001 -4.1000000000000000E+0001
- -4.1000000000000000E+0001 2.5000000000000000E+0001
- -1.7000000000000000E+0001 1.0000000000000000E+0001
- 1.0000000000000000E+0001 -6.0000000000000000E+0000
- -1.7000000000000000E+0001 1.0000000000000000E+0001
- 1.0000000000000000E+0001 -6.0000000000000000E+0000
- 5.0000000000000000E+0000 -3.0000000000000000E+0000
- -3.0000000000000000E+0000 2.0000000000000000E+0000
- \end{verbatim}
- \Precision
- The procedure doesn't supply information about the precision of the
- operation after termination.
- \Method
- The calculation of the inverse is based on Cholesky decomposition for a
- symmetrical positive definitie matrix.
- \References
- Wilkinson, J.H. and Reinsch, C.\\ Handbook for Automatic Computation.\\
- Volume II, Linear Algebra.\\ Springer Verlag, Contribution I/7, 1971.
- \end{procedure}
- \begin{procedure}{invgsy}
- \FunctionDescription
- Procedure to calculate the inverse of a symmetrical matrix.
- \Dataorganisation
- The procedure assumes that the calling program has declared a two
- dimensional matrix containing the maxtrixelements in (the bottomleft part
- of) a square partial block.
- \DeclarationandParams
- \lstinline|procedure invgsy(n, rwidth: ArbInt; var ai: ArbFloat;var term:ArbInt);|
- \begin{description}
- \item[n: integer] \mbox{ } \\
- The parameter {\bf n} describes the size of the matrix
- \item[rwidth: integer] \mbox{} \\
- The parameter {\bf rwidth} describes the declared rowlength of the twodimensional
- matrix.
- \item[var ai: real] \mbox{} \\
- The parameter {\bf ai} must contain to the twodimensional arrayelement
- that is top-left in the matrix.
- After the function has ended succesfully (\textbf{term=1}) then
- the input matrix has been changed into its inverse, otherwise the contents
- of the input matrix are undefined.
- ongedefinieerd.
- \item[var term: integer] \mbox{} \\
- After the procedure has run, this variable contains the reason for
- the termination of the procedure:\\
- {\bf term}=1, succesfull termination, the inverse has been calculated
- {\bf term}=2, inverse matrix could not be calculated because the matrix
- is (very close to) being singular.
- {\bf term}=3, wrong input n$<$1
- \end{description}
- \Remarks
- \begin{itemize}
- \item Only the bottomleft part of the matrix $A$ needs to be passed.
- \item \textbf{Warning} This procedure does not do array range checks. When called with invalid
- parameters, invalid/nonsense responses or even crashes may be the result.
- \end{itemize}
- \Example
- Het berekenen van de inverse van
- \[
- A=
- \left(
- \begin{array}{rrrr}
- 5 & 7 & 6 & 5 \\
- 7 & 10 & 8 & 7 \\
- 6 & 8 & 10 & 9 \\
- 5 & 7 & 9 & 10
- \end{array}
- \right)
- .
- \]
- \begin{lstlisting}
- program invgsyex;
- uses typ, iom, inv;
- const n = 4;
- var i, j, term : ArbInt;
- A : array[1..n,1..n] of ArbFloat;
- begin
- assign(input, paramstr(1)); reset(input);
- assign(output, paramstr(2)); rewrite(output);
- writeln('program results invgsyex');
- { Read bottomleft part of matrix A}
- for i:=1 to n do iomrev(input, A[i,1], i);
- { print matrix A}
- writeln; writeln('A =');
- for i:=1 to n do for j:=1 to i-1 do A[j,i]:=A[i,j];
- iomwrm(output, A[1,1], n, n, n, numdig);
- { calculate inverse of matrix A}
- invgsy(n, n, A[1,1], term);
- writeln; writeln('term=', term:2);
- if term=1 then
- { print inverse of matrix A}
- begin
- writeln; writeln('inverse of A =');
- iomwrm(output, A[1,1], n, n, n, numdig);
- end; {term=1}
- close(input); close(output)
- end.
- \end{lstlisting}
- \ProgramData
- \begin{verbatim}
- 5
- 7 10
- 6 8 10
- 5 7 9 10
- \end{verbatim}
- \ProgramResults
- \begin{verbatim}
- program results invgsyex
- A =
- 5.0000000000000000E+0000 7.0000000000000000E+0000
- 7.0000000000000000E+0000 1.0000000000000000E+0001
- 6.0000000000000000E+0000 8.0000000000000000E+0000
- 5.0000000000000000E+0000 7.0000000000000000E+0000
- 6.0000000000000000E+0000 5.0000000000000000E+0000
- 8.0000000000000000E+0000 7.0000000000000000E+0000
- 1.0000000000000000E+0001 9.0000000000000000E+0000
- 9.0000000000000000E+0000 1.0000000000000000E+0001
- term= 1
- inverse of A =
- 6.8000000000000001E+0001 -4.1000000000000001E+0001
- -4.1000000000000001E+0001 2.5000000000000000E+0001
- -1.7000000000000000E+0001 1.0000000000000000E+0001
- 1.0000000000000000E+0001 -6.0000000000000001E+0000
- -1.7000000000000000E+0001 1.0000000000000000E+0001
- 1.0000000000000000E+0001 -6.0000000000000001E+0000
- 5.0000000000000001E+0000 -3.0000000000000000E+0000
- -3.0000000000000000E+0000 2.0000000000000000E+0000
- \end{verbatim}
- \Precision
- The procedure doesn't supply information about the precision of the
- operation after termination.
- \Method
- The calculation of the inverse is based on reduction of a symmetrical
- matrix to a tridiagonal form.
- \References
- Aasen, J. O. \\
- On the reduction of a symmetric matrix to tridiagonal form. \\
- BIT, 11, (1971), pag. 223-242.
- \end{procedure}
- \end{document}
|