Unit mtx09

DescriptionusesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Unit to manage abstract matrix data in a Scilab/Matlab like way

TODO use html code here and link to Ooo presentation in html or pdf Introduction

This unit provides a matrix data type and functions to perform input/output and most simple matrix operations. * link to concept list *

The main goal is to achieve the compacity of scilab/matlab like code transparent dynamic memory management; simple unified IO NO messy formatting... just a pretty and ugly format ! Almost NO explicit loops through transparent dimension management;

Some definitions: plain mtx versus slice

function and procedure overloading

exceptions handling with assert (or returned value... a bit messy)

Understanding softdimensions dim. expansion and reduction by operator

For advanced users, some hooks are provided to use legacy scientific libraries such as fortran subroutines from netlib or the numerical constants, vector and matrix from the Gnu Scientific library.

TODO add pointers to urls with presentations and typical examples or tutorials and also memo for advanced usage or notes for developers

TODO see also similar projects such as eigen matpack the GSL and where this idea comes from ( technicalities from Braquelaire C programming... the old book about abstract data types when object programming was not yet born ! )

What are the main advantages over other softwares and limitations. Some words about R approach to i/o i.e. NO IO just keep everething together from one session to another in a given context/folder... persistence or simple I/O versus the spreadsheet way...

Simple IO easy interaction with shell scripts of all kinds and spreadsheets* as cut/paste works fine.

dark corners... potential memory leaks why use/not use the the fpc option to check memory leaks. The message: local mtx should only be assigned slices to avoid memory alloc in functions or procedures ( which will NOT be deallocated. One may use private mtx in implementation of user's units using mtx09.

references: abstract programming Braquelaire's book GSL manual may be pointers to wikipedia function/procedure overloading and or the official freePascal documentation.

Overview

Classes, Interfaces, Objects and Records

Name Description
record block  
record vector  
record matrix  
record mtx mtx: abstract matrix data type

Functions and Procedures

procedure fmt(d:longint); inline;
function reset(var f: text; s:string):boolean; inline;
procedure opn(s:string; var f:text); inline;
procedure apn(s:string; var f:text); inline;
procedure clo(var f:text); inline;
procedure reset(var f: text); inline;
function rewrite(var f: text; s:string): boolean; inline;
procedure rewrite(var f: text); inline;
function append(var f:text; s:string):boolean;
procedure append(var f: text); inline;
procedure nam(var a:mtx; name:string) inline;
function nam(a:mtx):string; inline;
function mwr(a:mtx; var f:text):boolean;
function mwr(a:mtx; s:string): boolean;
function mwr(a:mtx): boolean; inline;
function mwr(x:double): boolean; inline;
function mwr(x:double; var f:text): boolean; inline;
procedure mwr(s:string; var f:text); inline;
procedure mwr(s:string); inline;
procedure mwr(p:boolean; var f:text); inline;
procedure mwr(p:boolean); inline;
procedure rwr(nam:string); inline;
procedure rwr(p:boolean); inline;
procedure rwr(nam:string; var f:text); inline;
procedure tra(p: boolean); inline;
procedure tra; inline;
function ptr(a:mtx):Pdouble;
procedure mym(var r:mtx; var x:double; lgn, col:longint);
function mty(a:mtx):boolean; inline;
function col(a:mtx): longint; inline;
function lgn(a:mtx): longint; inline;
function elm(a:mtx; i, j: longint):double;
procedure elm(a:mtx; i, j: longint; x:double);
function elm(a:mtx; b:mtx):boolean;
procedure elm(b:mtx; x:double);
procedure elm(a:mtx; s:string);
function mrd(var r: mtx; var f: text; mnam:string): boolean;
function mrd(var r: mtx; var f: text): boolean; inline;
function mrd(var r:mtx):boolean;
function mrd(var r:mtx; sf:string; sm:string):boolean;
function mrd(var r:mtx; sf:string):boolean; inline;
function col(a:mtx; j: longint): mtx;
function col(a:mtx; j1, j2: longint): mtx;
function lgn(a:mtx; i1: longint): mtx;
function lgn(a:mtx; i1,i2: longint): mtx;
function lgn(a:mtx; low, high:double):mtx;
procedure lgn(var a:mtx; ri, rx:mtx); inline;
procedure lgn(var a:mtx; ri:mtx); inline;
function sli(a:mtx; l1, l2, c1, c2: longint): mtx; inline;
function trp(a:mtx):mtx;
function dia(a:mtx):mtx;
procedure zer(var r:mtx; lgn, col: longint); inline;
procedure zer(var r:mtx; a:mtx); inline;
procedure one(var r:mtx; lgn, col: longint); inline;
procedure one(var r:mtx; a:mtx); inline;
procedure eye(var r:mtx; lgn, col: longint);
procedure eye(var r:mtx; a:mtx); inline;
procedure lsp(var r:mtx; x0, x1: double; n:longint);
procedure lsp(a:mtx; x0, x1:double);
procedure equ(var r:mtx; x:double; m, n:longint); inline;
procedure equ(var r:mtx; x: double; a:mtx); inline;
procedure equ(var r:mtx; a:mtx); inline;
procedure equ(var r:mtx; s:string);
procedure cat(var r:mtx; a,b:mtx);
procedure cat(var r:mtx; a:mtx);
procedure stk(var r:mtx; a,b:mtx);
procedure stk(var r:mtx; a:mtx);
procedure mpt(a:mtx);
procedure mpt(a:mtx; s:string); inline;
procedure prd(var r: mtx; a, b: mtx);
function prd(a, b:mtx):double; inline;
function inv(var r:mtx; a:mtx; var d:double):boolean; inline;
function inv(a:mtx; var d:double):boolean; inline;
function spl( var s:mtx; x, y: mtx):boolean;
function sev(u:double; s:mtx):double;
function sev(var r:mtx; u:mtx; s:mtx):boolean;
function vec(a:mtx):Pvector;
function mat(a:mtx):Pmatrix;
procedure rex(var m:mtx; lo, hi: double);
procedure rex(var r:mtx; rx:mtx); inline;
procedure roi(var m:mtx; ri:mtx);
procedure rix(var r:mtx; ri, rx:mtx); inline;
procedure add(var r: mtx; a:mtx; b:mtx);
procedure add(var r: mtx; a:mtx; x:double);
procedure add(var r: mtx; x:double; a:mtx);
procedure add(a, b:mtx);
procedure add(a: mtx; x: double);
procedure add(var x: double; a:mtx);
procedure add(var r: mtx; a:mtx; p:boolean);
procedure sub(var r: mtx; a:mtx; b:mtx);
procedure sub(var r: mtx; a:mtx; x:double);
procedure sub(var r: mtx; x:double; a:mtx);
procedure sub(a, b:mtx);
procedure sub(a: mtx; x: double);
procedure sub(var x: double; a:mtx);
procedure sub(var r: mtx; a:mtx; p:boolean);
procedure mul(var r: mtx; a:mtx; b:mtx);
procedure mul(var r: mtx; a:mtx; x:double);
procedure mul(var r: mtx; x:double; a:mtx);
procedure mul(a, b:mtx);
procedure mul(a: mtx; x: double);
procedure mul(var x: double; a:mtx);
procedure mul(var r: mtx; a:mtx; p:boolean);
procedure dvd(var r: mtx; a:mtx; b:mtx);
procedure dvd(var r: mtx; a:mtx; x:double);
procedure dvd(var r: mtx; x:double; a:mtx);
procedure dvd(a, b:mtx);
procedure dvd(a: mtx; x: double);
procedure dvd(var x: double; a:mtx);
procedure dvd(var r: mtx; a:mtx; p:boolean);

Types

C_int = LongBool;
size_t = longint;
Pchar = ˆchar;
Pdouble = ˆdouble;
Pblock = ˆblock;
Pvector = ˆvector;
Pmatrix = ˆmatrix;

Constants

Infinity = 1e300;
ElmDelim=[' ',#9,','];
RowDelim=[';',#10];
EpsDouble = 1e-30;
WordDelim=[#0..' '];
BLANK=[#32,#9];
TAB=#9;

Description

Functions and Procedures

procedure fmt(d:longint); inline;

procedure fmt(d:longint); inline;
Control output format of numbers: pretty or ugly (but more accurate)
d=1
pretty output (default),
d=0
ugly but accurate output.
Example

function reset(var f: text; s:string):boolean; inline;

function reset(var f: text; s:string): boolean; inline;
Open text stream "f" to read from file named "s".
Returns false if it fails.
See also opn().
Example

procedure opn(s:string; var f:text); inline;

procedure opn(s:string; var f:text); inline;
Open text stream "f" to read from file named "s". Raises an error if it fails.
NOTE: see also reset()
Example

procedure apn(s:string; var f:text); inline;

procedure apn(s:string; var f:text); inline;
Open text stream "f" to append to file named "s".
See also: rwr() opn() clo()
Example

procedure clo(var f:text); inline;

Close text stream "f". An alias of system.close(). Raises an error if it fails.
See also: opn() rwr() mrd() mwr()
Example

procedure reset(var f: text); inline;

procedure reset(var f: text); inline;
Pristine freepascal reset: the freepascal standard way to open text streams:
Example

function rewrite(var f: text; s:string): boolean; inline;

function rewrite(var f: text; s:string): boolean; inline;
Open text stream "f" for writing to file "s". Return false if rewrite failed. One may wrap the call with assert() for a simple exception management: assert(rewrite(fo,onam))
Example

procedure rewrite(var f: text); inline;

procedure rewrite(var f: text); inline;
Pristine freepascal rewrite.
The freepascal standard way tp open text streams:
Example

function append(var f:text; s:string):boolean;

function append(var f:text; s:string):boolean;
This function enables to append to a file with a single instruction. It doesn't throw an error if the file named "s" doesn't exist unlike pristine freePascal append() but does a rewrite instead.
Example
See also freePascal append

procedure append(var f: text); inline;

procedure append(var f: text); inline;
Pristine freepascal append()
Example
See also the other avatar

procedure nam(var a:mtx; name:string) inline;

procedure nam(var p:mtx; name:string) inline;
assign a name to p
Example

function nam(a:mtx):string; inline;

function nam(p:mtx):string; inline;
return the name of "p"
Example

function mwr(a:mtx; var f:text):boolean;

function mwr(a:mtx; var f:text):boolean;
Write matrix "a" in text stream "f"
The text stream "f" MUST be opened by append or rewrite or apn() or rwr() short name equivalents.
Example

function mwr(a:mtx; s:string): boolean;

function mwr(a:mtx; s:string): boolean;
This function output (append) matrix "a" to the text file named "s".
If "s" is an empty string then stdout is used.
rwr(s) to rewrite from an empty file.
or change append mode to false with rwr(true) : overwrite or rwr(false) ( default behaviour of mwr(a,s) ) to append matrix "a" to file "s"
Example

function mwr(a:mtx): boolean; inline;

function mwr(a:mtx): boolean; inline;
Write mtx "a" to stdout.
Example

function mwr(x:double): boolean; inline;

function mwr(x:double): boolean; inline;
Write a formatted number to stdout (as a 1,1 mtx) with a trailing blank line.
Example

function mwr(x:double; var f:text): boolean; inline;

function mwr(x:double; var f:text): boolean; inline;
Write a formatted number to an opened text stream (as a 1,1 mtx) with a trailing blank line.
Example

procedure mwr(s:string; var f:text); inline;

procedure mwr(s:string; var f:text); inline;
Print string "s" into the open text stream "f".
Example

procedure mwr(s:string); inline;

procedure mwr(s:string); inline;
Print the string "s" into stdout.
Example

procedure mwr(p:boolean; var f:text); inline;

procedure mwr(p:boolean, var f:text); inline;
Print the boolean "p" into the opened text stream "f" as "TRUE" or "FALSE".
Example

procedure mwr(p:boolean); inline;

procedure mwr(p:boolean); inline;
Print the boolean "p" into stdout as 'TRUE' or 'FALSE'
Example

procedure rwr(nam:string); inline;

procedure rwr(nam:string); inline;
This procedure will empty the file "nam" or create it if doesn't exist.
Example

procedure rwr(p:boolean); inline;

procedure rwr(p:boolean); inline;
Modify append mode of mwr(a:mtx; s:string) procedure. Default is append, rwr(true) will modify this behaviour to write a single mtx in a blank file rather than appending to whatever pre-existing file. This flag will prevail for all mwr(mtx,string) avatar. An alternative is to clear a file with rwr(file_name) preserving the default append mode.
Example

procedure rwr(nam:string; var f:text); inline;

procedure rwr(nam:string; var f:text); inline;
This procedure will empty the file "nam" or create it if doesn't exist.
Example

procedure tra(p: boolean); inline;

procedure tra(p: boolean); inline;
Control trace mode; p=true/false : trace on/off When trace mode is on most functions will produce an information in standard output about the function name the dimensions of the const. mtx arguments and output the mtx result of the operation.
Example

procedure tra; inline;

procedure tra; inline;
toggle trace mode on/off. When trace mode is on most functions will produce an information in standard output about the function name and the dimensions of the mtx arguments.
Example

function ptr(a:mtx):Pdouble;

function ptr(a:mtx):Pdouble;
This function enables to use plain mtx in an external fortran procedure call.
Example
The fortran code used

procedure mym(var r:mtx; var x:double; lgn, col:longint);

procedure mym(var r:mtx; var x:double; lgn, col:longint);
Memory map: use static memory in mtx objects.
Matrix "r" is created using the memory starting at the location of the variable "x" with the given numbers or rows and columns (in arg. lgn and col). The number of elements of "r" must be equal or smaller than the static array used. The second argument "x" is a variable argument of type double typically the first element of the array: x[1]. This is usefull to alias a static pascal array of double with an mtx object. Some name convention may be used to highlight the connection between the mtx and the static array used.
Example

function mty(a:mtx):boolean; inline;

function mty(a:mtx):boolean; inline;
Return true if "a" is empty or not defined/allocated.
Example

function col(a:mtx): longint; inline;

function col(a:mtx): longint; inline;
Return the number of columns of "a".
Example

function lgn(a:mtx): longint; inline;

function lgn(a:mtx): longint; inline;
Return the number of rows (french: lignes) of a.
Example

function elm(a:mtx; i, j: longint):double;

function elm(a:mtx; i, j: longint):double;
Return a(i,j)
Example

procedure elm(a:mtx; i, j: longint; x:double);

procedure elm(a:mtx; i, j: longint; x:double);
Assign an element of a: a(i,j) = x
Example

function elm(a:mtx; b:mtx):boolean;

function elm(a:mtx; b:mtx):boolean;
a(i,j) = b(i,j) for all i,j
b has soft dimensions i.e. rows and/or columns will be duplicated so that it matches the dimensions of a, if it make sense: i.e. b may be (1,1) (1,n) or (m,1) if a is (m,n).
Example 1
Example 2

procedure elm(b:mtx; x:double);

procedure elm(b:mtx; x:double);
Fill "b" with value "x";
"b" must have dimensions. Intended usage: to fill a slice with some special value. e.g. elm( col(a,1), 0.0)
Example

procedure elm(a:mtx; s:string);

procedure elm(a:mtx; s:string);
assign elments of "a" with the values given in "s"; "a" can be a slice. The dimensions of "s" and "a" must match in the softdim sense.
Example

function mrd(var r: mtx; var f: text; mnam:string): boolean;

function mrd(var r: mtx; var f: text; mnam:string): boolean;
read in r a matrix named mnam from the opened text stream f.
return true if read was successfull.
Example

function mrd(var r: mtx; var f: text): boolean; inline;

function mrd(var r: mtx; var f: text): boolean; inline;
Read any matrix from text stream f in r; return true if successful.
Example

function mrd(var r:mtx):boolean;

function mrd(var r:mtx):boolean;
Read any matrix from stdin in r; return true if successful.
Example
Example

function mrd(var r:mtx; sf:string; sm:string):boolean;

function mrd(var r:mtx; sf:string; sm:string):boolean;
read "r" named "sm" from file "sf": return true if successful.
sm='*' : any matrix
sm='' : first anonymous matrix in file
Example

function mrd(var r:mtx; sf:string):boolean; inline;

function mrd(var r:mtx; sf:string):boolean; inline;
read "r" (first named or anonymous matrix) in the file "sf"; return true if successful.
Example

function col(a:mtx; j: longint): mtx;

function col(a:mtx; j1: longint): mtx;
Return a slice of a: a(:,j)
Example

function col(a:mtx; j1, j2: longint): mtx;

function col(a:mtx; j1, j2: longint): mtx;
Return a slice of a: a(:,j1:j2)
Example

function lgn(a:mtx; i1: longint): mtx;

function lgn(a:mtx; i1: longint): mtx;
Returns row "i1" of "a" (a slice of "a")
Example

function lgn(a:mtx; i1,i2: longint): mtx;

function lgn(a:mtx; i1,i2: longint): mtx;
Return a slice of "a", adjacent rows from i1 to i2.
Scilab: a(i1:i2,:)
Example

function lgn(a:mtx; low, high:double):mtx;

function lgn(a:mtx; low, high:double):mtx;
Return a row SLICE of a, defined by a low high bracket on the values of the first colum assumed to be monotonously increasing. a MUST be plain (not a slice).
Example

procedure lgn(var a:mtx; ri, rx:mtx); inline;

procedure lgn(var a:mtx; ri, rx:mtx);
TODO check this and preconditions... Selection and in situ deletion and shift of rows to select regions of interest in a histogram stored in "a". The first column of a must increase monotonously.
"ri": include rows if a(i,1) in any ri bracket "rx": exclude rows if a(i,1) in any rx bracket a should be plain (Warning: no sanity check done !)
replaced by rix() based on roi() and rex() cleaner/faster hopefully safer ! Example

procedure lgn(var a:mtx; ri:mtx); inline;

procedure lgn(var a:mtx; ri:mtx);
Select rows of interest depending on values in the 1st column of "a" compared with min max brackets given in each row of "ri". Note: "a" size may decrease by removing all lines not in the roi brackets. Assert that the first col "a" is sorted and monotonously increasing.
Obsolete use roi() instead Example

function sli(a:mtx; l1, l2, c1, c2: longint): mtx; inline;

function sli(a:mtx; l1, l2, c1, c2: longint): mtx;
Return a slice of a; same as Scilab a(l1:l2,c1:c2)
Example

function trp(a:mtx):mtx;

function trp(a:mtx):mtx;
Return a slice: transposed access to "a"

function dia(a:mtx):mtx;

function dia(a:mtx):mtx;
Return a slice: diagonal elements of "a"
"a" Must be a plain matrix.
Example

procedure zer(var r:mtx; lgn, col: longint); inline;

procedure zer(var r:mtx; lgn, col: longint); inline;
Create "r(lgn,col)" filled with 0;
Scilab: r = zeros(lgn,col);
Example

procedure zer(var r:mtx; a:mtx); inline;

procedure zer(var r:mtx; a:mtx); inline;
Create "r" same dimensions as "a" filled with 0;
Scilab: r=zeros(a)
Example

procedure one(var r:mtx; lgn, col: longint); inline;

procedure one(var r:mtx; lgn, col: longint); inline;
Create "r(lgn,col)" filled with 1.0;
Scilab: r = ones(lgn,col);
Example

procedure one(var r:mtx; a:mtx); inline;

procedure one(var r:mtx; a:mtx); inline;
Create "r" of the same dim. as "a" filled with 1.0;
Scilab: r=ones(a)
Example

procedure eye(var r:mtx; lgn, col: longint);

procedure eye(var r:mtx; lgn, col: longint);
Equivalent to Scilab r = eye(lgn,col)
Example

procedure eye(var r:mtx; a:mtx); inline;

procedure eye(var r:mtx; a:mtx); inline;
Equivalent to Scilab r = eye(a)
Example

procedure lsp(var r:mtx; x0, x1: double; n:longint);

procedure lsp(var r:mtx; x0, x1: double; n:longint);
Returns "r", a column vector of "n"+1 elements evenly spaced from "x0" to "x1". Same as Scilab's linspace() function.
Example

procedure lsp(a:mtx; x0, x1:double);

procedure lsp(a:mtx; x0, x1:double);
Enable to fill a column or row of a table with linearly spaced values. Intended use: lsp(col(table,1),0.0,100.0); to fill the first col. of a table with lin. spaced values of the independant variable.
Example

procedure equ(var r:mtx; x:double; m, n:longint); inline;

procedure equ(var r:mtx; x:double; m, n:longint); inline;
Create matrix "r" with "m" rows and "n" columns, with all elements equal to "x".
Example

procedure equ(var r:mtx; x: double; a:mtx); inline;

procedure equ(var r:mtx; x: double; a:mtx); inline;
Create matrix "r" of the same size as "a" all elements of "r" equal to "x".
Example

procedure equ(var r:mtx; a:mtx); inline;

procedure equ(var r:mtx; a:mtx); inline;
Create a copy "r" of matrix "a"; "r" will be a plain matrix whereas "a" can be a slice.
Example

procedure equ(var r:mtx; s:string);

procedure equ(var r:mtx; s:string);
Convert the string representation "s" of a matrix into "r"; Within a row elements are separated by spaces or commas and rows are separated by semi-colons.
Alternatively s can be filename[,mtxname] to read from. This is redundant with mrd() but convenient in certain cases e.g. to communicate a table of value smaal (big) in a command line option limited to 255 char. in free Pascal; Example

procedure cat(var r:mtx; a,b:mtx);

procedure cat(var r:mtx; a,b:mtx);
Matrix right concatenation.
Scilab: r = [a,b]
Example

procedure cat(var r:mtx; a:mtx);

procedure cat(var r:mtx; a:mtx);
Matrix right concatenation; i.e. r = [r,a] using Scilab notation.
Example

procedure stk(var r:mtx; a,b:mtx);

procedure stk(var r:mtx; a,b:mtx);
Stack "a" and "b" and copy in "r"; "a" and "b" must have the same number of columns.
Note: empty mtx are not handled properly, use the other avatar.
Scilab: r=[a;b]
Example

procedure stk(var r:mtx; a:mtx);

procedure stk(var r:mtx; a:mtx);
Append "a" below "r"; "a" and "r" must have the same number of columns or be empty.
Scilab: r = [r;a]
Example

procedure mpt(a:mtx);

output fields of a This procedure is intended for debug only.
Example

procedure mpt(a:mtx; s:string); inline;

output fields of a along with the comment string s This procedure is intended for debug only.
Example

procedure prd(var r: mtx; a, b: mtx);

procedure prd(var r: mtx; a, b: mtx);
matrix product; Scilab: r = a * b
The dimensions of "a" and "b" must be compatible with matrix product.
Example

function prd(a, b:mtx):double; inline;

function prd(a, b:mtx):double; inline;
Returns the scalar product of vectors "a" and "b"; any combination of row or column vectors with the same number of elements;
Example

function inv(var r:mtx; a:mtx; var d:double):boolean; inline;

function inv(var r:mtx; a:mtx; var d:double):boolean;
Matrix inversion by Gauss/Jordan with maximum pivot. The function returns true if successful.
  • r: inverse of a
  • a: plain mtx or a slice; not modified
  • d: determinant of a
Example

function inv(a:mtx; var d:double):boolean; inline;

function inv(a:mtx; var d:double):boolean; inline;
Matrix inversion by Gauss/Jordan with maximum pivot. The function returns true if successful.
  • a: plain mtx, inverted in situ.
  • d: determinant of "a"
Example

function spl( var s:mtx; x, y: mtx):boolean;

function spl( var s:mtx; x, y: mtx):boolean;
Wrapper of the fortran source.
  • x independant variable vector
  • y dependant variable vector
  • s the returnes spline table of coefficient
See also sev()
Example

function sev(u:double; s:mtx):double;

function sev(u:double; s:mtx):double;
  • "s" spline interpolation table calculated by spl
  • return: interpolated value for independant variable = "u"
Example

function sev(var r:mtx; u:mtx; s:mtx):boolean;

function sev(var r:mtx; u:mtx; s:mtx):boolean;
  • "r": interpolated table for the vector u and spline table s
  • "u": a vector sorted by increasing values of the independant variable
  • "u" must be plain or a compact slice (1 row but NOT 1 column).
  • "s": a cubic spline interpolation table calculated by spl()
  • return: always true (useless); note todo exception handling harmonisation ?
Example

function vec(a:mtx):Pvector;

map a mtx into a GSL vector pointer.

  • "a" a plain mtx (or compact slice TODO check this);
  • return a GSL's vector pointer.
The Gnu Scientific Library

function mat(a:mtx):Pmatrix;

function mat(a:mtx):Pmatrix;
map mtx "a" into a GSL matrix pointer (returned by the function).
Note: this is just a hook to use a very small part of the GSL library and mostly to test the concept. The Gnu Scientific Library

procedure rex(var m:mtx; lo, hi: double);

procedure rex(var m:mtx; lo, hi: double);
  
Example

procedure rex(var r:mtx; rx:mtx); inline;

procedure rex(var r:mtx; rx:mtx); inline;
Example

procedure roi(var m:mtx; ri:mtx);

  procedure roi(var m:mtx; ri:mtx);

Trim a table of data in one or several regions of interest. This function operates on tables (stored in matrix m) whose first column must be a monotonously increasing independant variable. Each row of ri (a 2 column matrix) defines a low and high bracket. Rows of m, whose independant variable (1st col.) is in none of the given brackets are discarded from m. The size of m will therefore eventually decrease.
Regions of interest may overlap, however the first column of ri must increase monotonously. Example

procedure rix(var r:mtx; ri, rx:mtx); inline;

  procedure rix(var r:mtx; ri, rx:mtx); inline;
Example

procedure add(var r: mtx; a:mtx; b:mtx);

procedure add(var r: mtx; a:mtx; b:mtx);
Element / element matrix operation: r = a + b
"a" and "b" must either have the same dimensions or be a row or column vector of the same size as "a" (or "b") or a (1,1) matrix. In the latter cases the row and/or column is duplicated so that the resulting operands have the same sizes; The result "r" dimensions will be that of the largest argument "a" or "b".
Example 1
Example 2
Example 3
Soft dimensions in arithmetic expressions

procedure add(var r: mtx; a:mtx; x:double);

procedure add(var r: mtx; a:mtx; x:double);
r(i,j) = a(i,j) + x
Example
Soft dimensions in arithmetic expressions

procedure add(var r: mtx; x:double; a:mtx);

procedure add(var r: mtx; x:double; a:mtx);
r(i,j) = x + a(i,j)
Example
Soft dimensions in arithmetic expressions

procedure add(a, b:mtx);

procedure add(a, b:mtx);
a = a + b
Example
Soft dimensions in arithmetic expressions

procedure add(a: mtx; x: double);

procedure add(a: mtx; x: double);
a = a + x
Example
Soft dimensions in arithmetic expressions

procedure add(var x: double; a:mtx);

procedure add(var x: double; a:mtx);
x += a(i,j) for all i,j
Example
Soft dimensions in arithmetic expressions

procedure add(var r: mtx; a:mtx; p:boolean);

procedure add(var r: mtx; a:mtx; p:boolean);
Cumulative operator + by row or column depending on p.
If p is true then the result r will have the size of a row of a else a column of a. The value of each element of r is the accumulation by the operator + of the element of the corresponding column ( row ) of a.
Example

procedure sub(var r: mtx; a:mtx; b:mtx);

procedure sub(var r: mtx; a:mtx; b:mtx);
Element / element matrix operation: r = a - b
"a" and "b" must either have the same dimensions or be a row or column vector of the same size as "a" (or "b") or a (1,1) matrix. In the latter cases the row and/or column is duplicated so that the resulting operands have the same sizes; The result "r" dimensions will be that of the largest argument "a" or "b".
Example 1
Example 2
Example 3
Soft dimensions in arithmetic expressions

procedure sub(var r: mtx; a:mtx; x:double);

procedure sub(var r: mtx; a:mtx; x:double);
r(i,j) = a(i,j) - x
Example
Soft dimensions in arithmetic expressions

procedure sub(var r: mtx; x:double; a:mtx);

procedure sub(var r: mtx; x:double; a:mtx);
r(i,j) = x - a(i,j)
Example
Soft dimensions in arithmetic expressions

procedure sub(a, b:mtx);

procedure sub(a, b:mtx);
a = a - b
Example
Soft dimensions in arithmetic expressions

procedure sub(a: mtx; x: double);

procedure sub(a: mtx; x: double);
a = a - x
Example
Soft dimensions in arithmetic expressions

procedure sub(var x: double; a:mtx);

procedure sub(var x: double; a:mtx);
x -= a(i,j) for all i,j
Example
Soft dimensions in arithmetic expressions

procedure sub(var r: mtx; a:mtx; p:boolean);

procedure sub(var r: mtx; a:mtx; p:boolean);
Cumulative operator - by row or column depending on p.
If p is true then the result r will have the size of a row of a else a column of a. The value of each element of r is the accumulation by the operator - of the element of the corresponding column ( row ) of a.
Example

procedure mul(var r: mtx; a:mtx; b:mtx);

procedure mul(var r: mtx; a:mtx; b:mtx);
Element / element matrix operation: r = a * b
"a" and "b" must either have the same dimensions or be a row or column vector of the same size as "a" (or "b") or a (1,1) matrix. In the latter cases the row and/or column is duplicated so that the resulting operands have the same sizes; The result "r" dimensions will be that of the largest argument "a" or "b".
Example 1
Example 2
Example 3
Soft dimensions in arithmetic expressions

procedure mul(var r: mtx; a:mtx; x:double);

procedure mul(var r: mtx; a:mtx; x:double);
r(i,j) = a(i,j) * x
Example
Soft dimensions in arithmetic expressions

procedure mul(var r: mtx; x:double; a:mtx);

procedure mul(var r: mtx; x:double; a:mtx);
r(i,j) = x * a(i,j)
Example
Soft dimensions in arithmetic expressions

procedure mul(a, b:mtx);

procedure mul(a, b:mtx);
a = a * b
Example
Soft dimensions in arithmetic expressions

procedure mul(a: mtx; x: double);

procedure mul(a: mtx; x: double);
a = a * x
Example
Soft dimensions in arithmetic expressions

procedure mul(var x: double; a:mtx);

procedure mul(var x: double; a:mtx);
x *= a(i,j) for all i,j
Example
Soft dimensions in arithmetic expressions

procedure mul(var r: mtx; a:mtx; p:boolean);

procedure mul(var r: mtx; a:mtx; p:boolean);
Cumulative operator * by row or column depending on p.
If p is true then the result r will have the size of a row of a else a column of a. The value of each element of r is the accumulation by the operator * of the element of the corresponding column ( row ) of a.
Example

procedure dvd(var r: mtx; a:mtx; b:mtx);

procedure dvd(var r: mtx; a:mtx; b:mtx);
Element / element matrix operation: r = a / b
"a" and "b" must either have the same dimensions or be a row or column vector of the same size as "a" (or "b") or a (1,1) matrix. In the latter cases the row and/or column is duplicated so that the resulting operands have the same sizes; The result "r" dimensions will be that of the largest argument "a" or "b".
Example 1
Example 2
Example 3
Soft dimensions in arithmetic expressions

procedure dvd(var r: mtx; a:mtx; x:double);

procedure dvd(var r: mtx; a:mtx; x:double);
r(i,j) = a(i,j) / x
Example
Soft dimensions in arithmetic expressions

procedure dvd(var r: mtx; x:double; a:mtx);

procedure dvd(var r: mtx; x:double; a:mtx);
r(i,j) = x / a(i,j)
Example
Soft dimensions in arithmetic expressions

procedure dvd(a, b:mtx);

procedure dvd(a, b:mtx);
a = a / b
Example
Soft dimensions in arithmetic expressions

procedure dvd(a: mtx; x: double);

procedure dvd(a: mtx; x: double);
a = a / x
Example
Soft dimensions in arithmetic expressions

procedure dvd(var x: double; a:mtx);

procedure dvd(var x: double; a:mtx);
x /= a(i,j) for all i,j
Example
Soft dimensions in arithmetic expressions

procedure dvd(var r: mtx; a:mtx; p:boolean);

procedure dvd(var r: mtx; a:mtx; p:boolean);
Cumulative operator / by row or column depending on p.
If p is true then the result r will have the size of a row of a else a column of a. The value of each element of r is the accumulation by the operator / of the element of the corresponding column ( row ) of a.
Example

Types

C_int = LongBool;

4 bytes to match C int type

size_t = longint;

TODO check if this is the best C<>fpc match

Pchar = ˆchar;

this type may be declared elsewhere

Pdouble = ˆdouble;

this type is already declared in fpc...

Pblock = ˆblock;
 
Pvector = ˆvector;
 
Pmatrix = ˆmatrix;
 

Constants

Infinity = 1e300;
 
ElmDelim=[' ',#9,','];

element delimiter within an ascii representation of a matrix

RowDelim=[';',#10];

row delimiter

EpsDouble = 1e-30;

TODO use HSL or GSL funct. or cst.

WordDelim=[#0..' '];

assert ascii char set TODO check where used

BLANK=[#32,#9];

spaces and tabs

TAB=#9;

ascii tab character used as delim in output


Generated by PasDoc 0.11.0 on 2010-10-04 16:33:27