home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / newmat06 / part01 < prev    next >
Encoding:
Text File  |  1992-12-06  |  60.6 KB  |  1,827 lines

  1. Newsgroups: comp.sources.misc
  2. From: robertd@kauri.vuw.ac.nz (Robert Davies)
  3. Subject:  v34i007:  newmat06 - A matrix package in C++, Part01/07
  4. Message-ID: <csm-v34i007=newmat06.224552@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 0c0ff11216b242d39d1473425f1ae2ce
  6. Date: Sun, 6 Dec 1992 04:46:44 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: robertd@kauri.vuw.ac.nz (Robert Davies)
  10. Posting-number: Volume 34, Issue 7
  11. Archive-name: newmat06/part01
  12. Environment: C++
  13. Supersedes: newmat04: Volume 26, Issue 87-91
  14.  
  15. An experimental matrix package in C++, newmat supports the matrix 
  16. types: Matrix, UpperTriangularMatrix, LowerTriangularMatrix, 
  17. DiagonalMatrix, SymmetricMatrix, RowVector, ColumnVector, BandMatrix,
  18. UpperBandMatrix, LowerBandMatrix, and SymmetricBandMatrix. 
  19. Only one element type (float or double) is supported.
  20.  
  21. The package includes the operations *, +, -, (defined as operators)
  22. inverse, transpose, conversion between types, submatrix, determinant,
  23. Cholesky decomposition, Householder triangularisation, singular value
  24. decomposition, eigenvalues of a symmetric matrix, sorting, fast fourier
  25. transform, printing and an interface with "Numerical Recipes in C".
  26.  
  27. It is intended for matrices in the range 4 x 4 up to the size your
  28. computer can store in one block.
  29. ---
  30. #! /bin/sh
  31. # This is a shell archive.  Remove anything before this line, then unpack
  32. # it by saving it into a file and typing "sh file".  To overwrite existing
  33. # files, type "sh file -c".  You can also feed this as standard input via
  34. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  35. # will see the following message at the end:
  36. #        "End of archive 1 (of 7)."
  37. # Contents:  example.cxx example.mak example.txt newmata.txt readme
  38. # Wrapped by robert@kea on Thu Dec  3 22:36:14 1992
  39. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  40. if test -f 'example.cxx' -a "${1}" != "-c" ; then 
  41.   echo shar: Will not clobber existing file \"'example.cxx'\"
  42. else
  43. echo shar: Extracting \"'example.cxx'\" \(9602 characters\)
  44. sed "s/^X//" >'example.cxx' <<'END_OF_FILE'
  45. X//$$ example.cxx                             Example of use of matrix package
  46. X
  47. X#define WANT_STREAM                  // include.h will get stream fns
  48. X#define WANT_MATH                    // include.h will get math fns
  49. X
  50. X#include "include.h"                 // include standard files
  51. X
  52. X#include "newmatap.h"                // need matrix applications
  53. X
  54. XReal t3(Real);                       // round to 3 decimal places
  55. X
  56. X
  57. X// demonstration of matrix package on linear regression problem
  58. X
  59. X
  60. Xvoid test1(Real* y, Real* x1, Real* x2, int nobs, int npred)
  61. X{
  62. X   cout << "\n\nTest 1 - traditional\n";
  63. X
  64. X   // traditional sum of squares and products method of calculation
  65. X   // with subtraction of means
  66. X
  67. X   // make matrix of predictor values
  68. X   Matrix X(nobs,npred);
  69. X
  70. X   // load x1 and x2 into X
  71. X   //    [use << rather than = with submatrices and/or loading arrays]
  72. X   X.Column(1) << x1;  X.Column(2) << x2;
  73. X
  74. X   // vector of Y values
  75. X   ColumnVector Y(nobs); Y << y;
  76. X
  77. X   // make vector of 1s
  78. X   ColumnVector Ones(nobs); Ones = 1.0;
  79. X
  80. X   // calculate means (averages) of x1 and x2 [ .t() takes transpose]
  81. X   RowVector M = Ones.t() * X / nobs;
  82. X
  83. X   // and subtract means from x1 and x1
  84. X   Matrix XC(nobs,npred);
  85. X   XC = X - Ones * M;
  86. X
  87. X   // do the same to Y [need "Real" to convert 1x1 matrix to scalar]
  88. X   ColumnVector YC(nobs);
  89. X   Real m = (Ones.t() * Y).AsScalar() / nobs;  YC = Y - Ones * m;
  90. X
  91. X   // form sum of squares and product matrix
  92. X   //    [use << rather than = for copying Matrix into SymmetricMatrix]
  93. X   SymmetricMatrix SSQ; SSQ << XC.t() * XC;
  94. X
  95. X   // calculate estimate
  96. X   //    [bracket last two terms to force this multiplication first]
  97. X   //    [ .i() means inverse, but inverse is not explicity calculated]
  98. X   ColumnVector A = SSQ.i() * (XC.t() * YC);
  99. X
  100. X   // calculate estimate of constant term
  101. X   Real a = m - (M * A).AsScalar();
  102. X
  103. X   // Get variances of estimates from diagonal elements of invoice of SSQ
  104. X   //    [ we are taking inverse of SSQ; would have been better to use
  105. X   //        CroutMatrix method - see documentation ]
  106. X   Matrix ISSQ = SSQ.i(); DiagonalMatrix D; D << ISSQ;
  107. X   ColumnVector V = D.AsColumn();
  108. X   Real v = 1.0/nobs + (M * ISSQ * M.t()).AsScalar();
  109. X                        // for calc variance const
  110. X
  111. X   // Calculate fitted values and residuals
  112. X   int npred1 = npred+1;
  113. X   ColumnVector Fitted = X * A + a;
  114. X   ColumnVector Residual = Y - Fitted;
  115. X   Real ResVar = Residual.SumSquare() / (nobs-npred1);
  116. X
  117. X   // Get diagonals of Hat matrix (an expensive way of doing this)
  118. X   Matrix X1(nobs,npred1); X1.Column(1)<<Ones; X1.Columns(2,npred1)<<X;
  119. X   DiagonalMatrix Hat;  Hat << X1 * (X1.t() * X1).i() * X1.t();
  120. X
  121. X   // print out answers
  122. X   cout << "\nEstimates and their standard errors\n\n";
  123. X   cout << a <<"\t"<< sqrt(v*ResVar) << "\n";
  124. X   for (int i=1; i<=npred; i++)
  125. X   cout << A(i) <<"\t"<< sqrt(V(i)*ResVar) << "\n";
  126. X   cout << "\nObservations, fitted value, residual value, hat value\n";
  127. X   for (i=1; i<=nobs; i++)
  128. X      cout << X(i,1) <<"\t"<< X(i,2) <<"\t"<< Y(i) <<"\t"<<
  129. X      t3(Fitted(i)) <<"\t"<< t3(Residual(i)) <<"\t"<< t3(Hat(i)) <<"\n";
  130. X   cout << "\n\n";
  131. X}
  132. X
  133. Xvoid test2(Real* y, Real* x1, Real* x2, int nobs, int npred)
  134. X{
  135. X   cout << "\n\nTest 2 - Cholesky\n";
  136. X
  137. X   // traditional sum of squares and products method of calculation
  138. X   // with subtraction of means - using Cholesky decomposition
  139. X
  140. X   Matrix X(nobs,npred);
  141. X   X.Column(1) << x1;  X.Column(2) << x2;
  142. X   ColumnVector Y(nobs); Y << y;
  143. X   ColumnVector Ones(nobs); Ones = 1.0;
  144. X   RowVector M = Ones.t() * X / nobs;
  145. X   Matrix XC(nobs,npred);
  146. X   XC = X - Ones * M;
  147. X   ColumnVector YC(nobs);
  148. X   Real m = (Ones.t() * Y).AsScalar() / nobs;  YC = Y - Ones * m;
  149. X   SymmetricMatrix SSQ; SSQ << XC.t() * XC;
  150. X
  151. X   // Cholesky decomposition of SSQ
  152. X   LowerTriangularMatrix L = Cholesky(SSQ);
  153. X
  154. X   // calculate estimate
  155. X   ColumnVector A = L.t().i() * (L.i() * (XC.t() * YC));
  156. X
  157. X   // calculate estimate of constant term
  158. X   Real a = m - (M * A).AsScalar();
  159. X
  160. X   // Get variances of estimates from diagonal elements of invoice of SSQ
  161. X   DiagonalMatrix D; D << L.t().i() * L.i();
  162. X   ColumnVector V = D.AsColumn();
  163. X   Real v = 1.0/nobs + (L.i() * M.t()).SumSquare();
  164. X
  165. X   // Calculate fitted values and residuals
  166. X   int npred1 = npred+1;
  167. X   ColumnVector Fitted = X * A + a;
  168. X   ColumnVector Residual = Y - Fitted;
  169. X   Real ResVar = Residual.SumSquare() / (nobs-npred1);
  170. X
  171. X   // Get diagonals of Hat matrix (an expensive way of doing this)
  172. X   Matrix X1(nobs,npred1); X1.Column(1)<<Ones; X1.Columns(2,npred1)<<X;
  173. X   DiagonalMatrix Hat;  Hat << X1 * (X1.t() * X1).i() * X1.t();
  174. X
  175. X   // print out answers
  176. X   cout << "\nEstimates and their standard errors\n\n";
  177. X   cout << a <<"\t"<< sqrt(v*ResVar) << "\n";
  178. X   for (int i=1; i<=npred; i++)
  179. X      cout << A(i) <<"\t"<< sqrt(V(i)*ResVar) << "\n";
  180. X   cout << "\nObservations, fitted value, residual value, hat value\n";
  181. X   for (i=1; i<=nobs; i++)
  182. X      cout << X(i,1) <<"\t"<< X(i,2) <<"\t"<< Y(i) <<"\t"<<
  183. X      t3(Fitted(i)) <<"\t"<< t3(Residual(i)) <<"\t"<< t3(Hat(i)) <<"\n";
  184. X   cout << "\n\n";
  185. X}
  186. X
  187. Xvoid test3(Real* y, Real* x1, Real* x2, int nobs, int npred)
  188. X{
  189. X   cout << "\n\nTest 3 - Householder triangularisation\n";
  190. X
  191. X   // Householder triangularisation method
  192. X   // load data - 1s into col 1 of matrix
  193. X   int npred1 = npred+1;
  194. X   Matrix X(nobs,npred1); ColumnVector Y(nobs);
  195. X   X.Column(1) << 1.0;  X.Column(2) << x1;  X.Column(3) << x2;  Y << y;
  196. X
  197. X   // do Householder triangularisation
  198. X   // no need to deal with constant term separately
  199. X   Matrix XT = X.t();             // Want data to be along rows
  200. X   RowVector YT = Y.t();
  201. X   LowerTriangularMatrix L; RowVector M;
  202. X   HHDecompose(XT, L); HHDecompose(XT, YT, M); // YT now contains resids
  203. X   ColumnVector A = L.t().i() * M.t();
  204. X   ColumnVector Fitted = X * A;
  205. X   Real ResVar = YT.SumSquare() / (nobs-npred1);
  206. X
  207. X   // get variances of estimates
  208. X   L = L.i(); DiagonalMatrix D; D << L.t() * L;
  209. X
  210. X   // Get diagonals of Hat matrix
  211. X   DiagonalMatrix Hat;  Hat << XT.t() * XT;
  212. X
  213. X   // print out answers
  214. X   cout << "\nEstimates and their standard errors\n\n";
  215. X   for (int i=1; i<=npred1; i++)
  216. X      cout << A(i) <<"\t"<< sqrt(D(i)*ResVar) << "\n";
  217. X   cout << "\nObservations, fitted value, residual value, hat value\n";
  218. X   for (i=1; i<=nobs; i++)
  219. X      cout << X(i,2) <<"\t"<< X(i,3) <<"\t"<< Y(i) <<"\t"<<
  220. X      t3(Fitted(i)) <<"\t"<< t3(YT(i)) <<"\t"<< t3(Hat(i)) <<"\n";
  221. X   cout << "\n\n";
  222. X}
  223. X
  224. Xvoid test4(Real* y, Real* x1, Real* x2, int nobs, int npred)
  225. X{
  226. X   cout << "\n\nTest 4 - singular value\n";
  227. X
  228. X   // Singular value decomposition method
  229. X   // load data - 1s into col 1 of matrix
  230. X   int npred1 = npred+1;
  231. X   Matrix X(nobs,npred1); ColumnVector Y(nobs);
  232. X   X.Column(1) << 1.0;  X.Column(2) << x1;  X.Column(3) << x2;  Y << y;
  233. X
  234. X   // do SVD
  235. X   Matrix U, V; DiagonalMatrix D;
  236. X   SVD(X,D,U,V);                              // X = U * D * V.t()
  237. X   ColumnVector Fitted = U.t() * Y;
  238. X   ColumnVector A = V * ( D.i() * Fitted );
  239. X   Fitted = U * Fitted;
  240. X   ColumnVector Residual = Y - Fitted;
  241. X   Real ResVar = Residual.SumSquare() / (nobs-npred1);
  242. X
  243. X   // get variances of estimates
  244. X   D << V * (D * D).i() * V.t();
  245. X
  246. X   // Get diagonals of Hat matrix
  247. X   DiagonalMatrix Hat;  Hat << U * U.t();
  248. X
  249. X   // print out answers
  250. X   cout << "\nEstimates and their standard errors\n\n";
  251. X   for (int i=1; i<=npred1; i++)
  252. X      cout << A(i) <<"\t"<< sqrt(D(i)*ResVar) << "\n";
  253. X   cout << "\nObservations, fitted value, residual value, hat value\n";
  254. X   for (i=1; i<=nobs; i++)
  255. X      cout << X(i,2) <<"\t"<< X(i,3) <<"\t"<< Y(i) <<"\t"<<
  256. X      t3(Fitted(i)) <<"\t"<< t3(Residual(i)) <<"\t"<< t3(Hat(i)) <<"\n";
  257. X   cout << "\n\n";
  258. X}
  259. X
  260. Xmain()
  261. X{
  262. X   cout << "\nDemonstration of Matrix package\n\n";
  263. X
  264. X   // Test for any memory not deallocated after running this program
  265. X   Real* s1; { ColumnVector A(8000); s1 = A.Store(); }
  266. X
  267. X   {
  268. X      // the data
  269. X      // you may need to read this data using cin if you are using a
  270. X      // compiler that doesn't understand aggregates
  271. X#ifndef ATandT
  272. X      Real y[]  = { 8.3, 5.5, 8.0, 8.5, 5.7, 4.4, 6.3, 7.9, 9.1 };
  273. X      Real x1[] = { 2.4, 1.8, 2.4, 3.0, 2.0, 1.2, 2.0, 2.7, 3.6 };
  274. X      Real x2[] = { 1.7, 0.9, 1.6, 1.9, 0.5, 0.6, 1.1, 1.0, 0.5 };
  275. X#else
  276. X      Real y[9], x1[9], x2[9];
  277. X      y[0]=8.3; y[1]=5.5; y[2]=8.0; y[3]=8.5; y[4]=5.7;
  278. X      y[5]=4.4; y[6]=6.3; y[7]=7.9; y[8]=9.1;
  279. X      x1[0]=2.4; x1[1]=1.8; x1[2]=2.4; x1[3]=3.0; x1[4]=2.0;
  280. X      x1[5]=1.2; x1[6]=2.0; x1[7]=2.7; x1[8]=3.6;
  281. X      x2[0]=1.7; x2[1]=0.9; x2[2]=1.6; x2[3]=1.9; x2[4]=0.5;
  282. X      x2[5]=0.6; x2[6]=1.1; x2[7]=1.0; x2[8]=0.5;
  283. X#endif
  284. X      int nobs = 9;                           // number of observations
  285. X      int npred = 2;                          // number of predictor values
  286. X
  287. X      // we want to find the values of a,a1,a2 to give the best
  288. X      // fit of y[i] with a0 + a1*x1[i] + a2*x2[i]
  289. X      // Also print diagonal elements of hat matrix, X*(X.t()*X).i()*X.t()
  290. X
  291. X      // this example demonstrates four methods of calculation
  292. X
  293. X      Try
  294. X      {
  295. X         test1(y, x1, x2, nobs, npred);
  296. X         test2(y, x1, x2, nobs, npred);
  297. X         test3(y, x1, x2, nobs, npred);
  298. X         test4(y, x1, x2, nobs, npred);
  299. X      }
  300. X      Catch(DataException) { cout << "\nInvalid data\n"; }
  301. X      Catch(SpaceException) { cout << "\nMemory exhausted\n"; }
  302. X      CatchAll { cout << "\nUnexpected program failure\n"; }
  303. X   }
  304. X
  305. X#ifdef DO_FREE_CHECK
  306. X   FreeCheck::Status();
  307. X#endif
  308. X   Real* s2; { ColumnVector A(8000); s2 = A.Store(); }
  309. X   cout << "\n\nChecking for lost memory: "
  310. X      << (unsigned long)s1 << " " << (unsigned long)s2 << " ";
  311. X   if (s1 != s2) cout << " - error\n"; else cout << " - ok\n";
  312. X
  313. X   return 0;
  314. X
  315. X}
  316. X
  317. XReal t3(Real r) { return int(r*1000) / 1000.0; }
  318. END_OF_FILE
  319. if test 9602 -ne `wc -c <'example.cxx'`; then
  320.     echo shar: \"'example.cxx'\" unpacked with wrong size!
  321. fi
  322. # end of 'example.cxx'
  323. fi
  324. if test -f 'example.mak' -a "${1}" != "-c" ; then 
  325.   echo shar: Will not clobber existing file \"'example.mak'\"
  326. else
  327. echo shar: Extracting \"'example.mak'\" \(1654 characters\)
  328. sed "s/^X//" >'example.mak' <<'END_OF_FILE'
  329. X
  330. XOBJ  =  example.o                                          \
  331. X        cholesky.o evalue.o fft.o hholder.o jacobi.o       \
  332. X        newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o  \
  333. X        newmat6.o newmat7.o newmat8.o newmatrm.o           \
  334. X        sort.o submat.o svd.o bandmat.o except.o newmatex.o
  335. X
  336. Xexample:      $(OBJ)
  337. X          g++ -o $@ $(OBJ) -lm
  338. X
  339. X%.o:          %.cxx
  340. X          g++ -c $*.cxx
  341. X
  342. Xnewmatxx:     include.h newmat.h boolean.h except.h
  343. X          rm -f newmatxx
  344. X          echo "main .h files uptodate?" > newmatxx
  345. X
  346. Xexcept.o:     except.h except.cxx
  347. X
  348. Xnewmatex.o:   newmatxx newmatex.cxx
  349. X
  350. Xexample.o:    newmatxx newmatap.h example.cxx
  351. X
  352. Xcholesky.o:   newmatxx cholesky.cxx
  353. X
  354. Xevalue.o:     newmatxx newmatrm.h precisio.h evalue.cxx
  355. X
  356. Xfft.o:        newmatxx newmatap.h fft.cxx
  357. X
  358. Xhholder.o:    newmatxx newmatap.h hholder.cxx
  359. X
  360. Xjacobi.o:     newmatxx precisio.h newmatrm.h jacobi.cxx
  361. X
  362. Xbandmat.o:    newmatxx newmatrc.h controlw.h bandmat.cxx
  363. X
  364. Xnewmat1.o:    newmatxx newmat1.cxx
  365. X
  366. Xnewmat2.o:    newmatxx newmatrc.h controlw.h newmat2.cxx
  367. X
  368. Xnewmat3.o:    newmatxx newmatrc.h controlw.h newmat3.cxx
  369. X
  370. Xnewmat4.o:    newmatxx newmatrc.h controlw.h newmat4.cxx
  371. X
  372. Xnewmat5.o:    newmatxx newmatrc.h controlw.h newmat5.cxx
  373. X
  374. Xnewmat6.o:    newmatxx newmatrc.h controlw.h newmat6.cxx
  375. X
  376. Xnewmat7.o:    newmatxx newmatrc.h controlw.h newmat7.cxx
  377. X
  378. Xnewmat8.o:    newmatxx newmatap.h newmat8.cxx
  379. X
  380. Xnewmat9.o:    newmatxx newmatrc.h controlw.h newmatio.h newmat9.cxx
  381. X
  382. Xnewmatrm.o:   newmatxx newmatrm.h newmatrm.cxx
  383. X
  384. Xsort.o:       newmatxx newmatap.h sort.cxx
  385. X
  386. Xsubmat.o:     newmatxx newmatrc.h controlw.h submat.cxx
  387. X
  388. Xsvd.o:        newmatxx newmatrm.h precisio.h svd.cxx
  389. X
  390. X
  391. X
  392. X
  393. X
  394. X
  395. X
  396. X
  397. X
  398. X
  399. X
  400. X
  401. END_OF_FILE
  402. if test 1654 -ne `wc -c <'example.mak'`; then
  403.     echo shar: \"'example.mak'\" unpacked with wrong size!
  404. fi
  405. # end of 'example.mak'
  406. fi
  407. if test -f 'example.txt' -a "${1}" != "-c" ; then 
  408.   echo shar: Will not clobber existing file \"'example.txt'\"
  409. else
  410. echo shar: Extracting \"'example.txt'\" \(1834 characters\)
  411. sed "s/^X//" >'example.txt' <<'END_OF_FILE'
  412. X
  413. XDemonstration of Matrix package
  414. X
  415. X
  416. X
  417. XTest 1 - traditional
  418. X
  419. XEstimates and their standard errors
  420. X
  421. X1.391655    0.531878
  422. X1.983103    0.209317
  423. X0.952208    0.277307
  424. X
  425. XObservations, fitted value, residual value, hat value
  426. X2.4    1.7    8.3    7.769    0.53    0.28
  427. X1.8    0.9    5.5    5.818    -0.318    0.189
  428. X2.4    1.6    8    7.674    0.325    0.228
  429. X3    1.9    8.5    9.15    -0.65    0.445
  430. X2    0.5    5.7    5.833    -0.133    0.271
  431. X1.2    0.6    4.4    4.342    0.057    0.479
  432. X2    1.1    6.3    6.405    -0.105    0.143
  433. X2.7    1    7.9    7.698    0.201    0.153
  434. X3.6    0.5    9.1    9.006    0.093    0.807
  435. X
  436. X
  437. X
  438. X
  439. XTest 2 - Cholesky
  440. X
  441. XEstimates and their standard errors
  442. X
  443. X1.391655    0.531878
  444. X1.983103    0.209317
  445. X0.952208    0.277307
  446. X
  447. XObservations, fitted value, residual value, hat value
  448. X2.4    1.7    8.3    7.769    0.53    0.28
  449. X1.8    0.9    5.5    5.818    -0.318    0.189
  450. X2.4    1.6    8    7.674    0.325    0.228
  451. X3    1.9    8.5    9.15    -0.65    0.445
  452. X2    0.5    5.7    5.833    -0.133    0.271
  453. X1.2    0.6    4.4    4.342    0.057    0.479
  454. X2    1.1    6.3    6.405    -0.105    0.143
  455. X2.7    1    7.9    7.698    0.201    0.153
  456. X3.6    0.5    9.1    9.006    0.093    0.807
  457. X
  458. X
  459. X
  460. X
  461. XTest 3 - Householder triangularisation
  462. X
  463. XEstimates and their standard errors
  464. X
  465. X1.391655    0.531878
  466. X1.983103    0.209317
  467. X0.952208    0.277307
  468. X
  469. XObservations, fitted value, residual value, hat value
  470. X2.4    1.7    8.3    7.769    0.53    0.28
  471. X1.8    0.9    5.5    5.818    -0.318    0.189
  472. X2.4    1.6    8    7.674    0.325    0.228
  473. X3    1.9    8.5    9.15    -0.65    0.445
  474. X2    0.5    5.7    5.833    -0.133    0.271
  475. X1.2    0.6    4.4    4.342    0.057    0.479
  476. X2    1.1    6.3    6.405    -0.105    0.143
  477. X2.7    1    7.9    7.698    0.201    0.153
  478. X3.6    0.5    9.1    9.006    0.093    0.807
  479. X
  480. X
  481. X
  482. X
  483. XTest 4 - singular value
  484. X
  485. XEstimates and their standard errors
  486. X
  487. X1.391655    0.531878
  488. X1.983103    0.209317
  489. X0.952208    0.277307
  490. X
  491. XObservations, fitted value, residual value, hat value
  492. X2.4    1.7    8.3    7.769    0.53    0.28
  493. X1.8    0.9    5.5    5.818    -0.318    0.189
  494. X2.4    1.6    8    7.674    0.325    0.228
  495. X3    1.9    8.5    9.15    -0.65    0.445
  496. X2    0.5    5.7    5.833    -0.133    0.271
  497. X1.2    0.6    4.4    4.342    0.057    0.479
  498. X2    1.1    6.3    6.405    -0.105    0.143
  499. X2.7    1    7.9    7.698    0.201    0.153
  500. X3.6    0.5    9.1    9.006    0.093    0.807
  501. X
  502. X
  503. X
  504. X
  505. XChecking for lost memory: 587792388 587792388  - ok
  506. END_OF_FILE
  507. if test 1834 -ne `wc -c <'example.txt'`; then
  508.     echo shar: \"'example.txt'\" unpacked with wrong size!
  509. fi
  510. # end of 'example.txt'
  511. fi
  512. if test -f 'newmata.txt' -a "${1}" != "-c" ; then 
  513.   echo shar: Will not clobber existing file \"'newmata.txt'\"
  514. else
  515. echo shar: Extracting \"'newmata.txt'\" \(42666 characters\)
  516. sed "s/^X//" >'newmata.txt' <<'END_OF_FILE'
  517. X//$$ newmata.txt                                   Documentation file
  518. X
  519. X
  520. X   Documentation for newmat06, an experimental matrix package in C++.
  521. X   ==================================================================
  522. X
  523. X
  524. XMATRIX PACKAGE                                           1 December, 1992
  525. X
  526. XCopyright (C) 1991,2: R B Davies
  527. X
  528. XPermission is granted to use but not to sell.
  529. X
  530. X
  531. XContents
  532. X========
  533. X
  534. XGeneral description
  535. XIs this the package you need?
  536. XChanges
  537. XWhere you can get a copy of this package
  538. XCompiler performance
  539. XExample
  540. XDetailed documentation
  541. X   Customising
  542. X   Constructors
  543. X   Elements of matrices
  544. X   Matrix copy
  545. X   Unary operators
  546. X   Binary operators
  547. X   Combination of a matrix and scalar
  548. X   Scalar functions of matrices
  549. X   Submatrix operations
  550. X   Change dimensions
  551. X   Change type
  552. X   Multiple matrix solve
  553. X   Memory management
  554. X   Output
  555. X   Accessing matrices of unspecified type
  556. X   Cholesky decomposition
  557. X   Householder triangularisation
  558. X   Singular Value Decomposition
  559. X   Eigenvalues
  560. X   Sorting
  561. X   Fast Fourier Transform
  562. X   Interface to Numerical Recipes in C
  563. X   Exceptions
  564. X   Clean up following an exception
  565. XList of files
  566. XProblem report form
  567. X
  568. X
  569. X---------------------------------------------------------------------------
  570. X
  571. X
  572. XGeneral description
  573. X===================
  574. X
  575. XThe package is intented for scientists and engineers who need to
  576. Xmanipulate a variety of types of matrices using standard matrix
  577. Xoperations. Emphasis is on the kind of operations needed in statistical
  578. Xcalculations such as least squares, linear equation solve and
  579. Xeigenvalues.
  580. X
  581. XIt supports matrix types
  582. X
  583. X    Matrix                       (rectangular matrix)
  584. X    nricMatrix                   (variant of rectangular matrix)
  585. X    UpperTriangularMatrix
  586. X    LowerTriangularMatrix
  587. X    DiagonalMatrix
  588. X    SymmetricMatrix
  589. X    BandMatrix
  590. X    UpperBandMatrix              (upper triangular band matrix)
  591. X    LowerBandMatrix              (lower triangular band matrix)
  592. X    SymmetricBandMatrix
  593. X    RowVector                    (derived from Matrix)
  594. X    ColumnVector                 (derived from Matrix).
  595. X
  596. XOnly one element type (float or double) is supported.
  597. X
  598. XThe package includes the operations *, +, -, inverse, transpose,
  599. Xconversion between types, submatrix, determinant, Cholesky
  600. Xdecomposition, Householder triangularisation, singular value
  601. Xdecomposition, eigenvalues of a symmetric matrix, sorting, fast fourier
  602. Xtransform, printing and an interface with "Numerical Recipes in C".
  603. X
  604. XIt is intended for matrices in the range 4 x 4 to the maximum size your
  605. Xmachine will accomodate in a single array. That is 90 x 90 (125 x 125
  606. Xfor triangular matrices) in machines that have 8192 doubles as the
  607. Xmaximum size of an array. It will work for very small matrices but
  608. Xbecomes rather inefficient.
  609. X
  610. XA two-stage approach to evaluating matrix expressions is used to improve
  611. Xefficiency and reduce use of temporary storage.
  612. X
  613. XThe package is designed for version 2 or 3 of C++. It works with Borland
  614. XC++ on a PC and AT&T C++ (2.1 & 3) and Gnu C++ (2.2) on a Sun. It works
  615. Xwith some problems with Zortech C++ (version 3).
  616. X
  617. X
  618. X---------------------------------------------------------------------------
  619. X
  620. X
  621. XIs this the package you need?
  622. X=============================
  623. X
  624. XDo you
  625. X
  626. X1.   need matrix operators such as * and + defined as operators so you
  627. X     can write things like
  628. X
  629. X        X  = A * (B + C);
  630. X
  631. X2.   need a variety of types of matrices
  632. X
  633. X3.   need only one element type (float or double)
  634. X
  635. X4.   work with matrices in the range 4x4 to 90x90
  636. X
  637. X5.   tolerate a large package
  638. X
  639. X
  640. XThen maybe this is the right package for you. 
  641. X
  642. XIf you don't need (1) then there may be better options. Likewise if you
  643. Xdon't need (2) there may be better options. If you require "not (5)"
  644. Xthen this is not the package for you.
  645. X
  646. X
  647. XIf you need (2) and "not (3)" and have some spare money, then maybe you
  648. Xshould look at M++ from Dyad or the Rogue Wave matrix package.
  649. X
  650. X
  651. XIf you need not (4); that is very large matrices that will need to be
  652. Xstored on disk, there is a package YAMP on CompuServe under the Borland
  653. XC++ library that might be of interest.
  654. X
  655. X
  656. XDetails of some other free C or C++ matrix packages follow - extracted
  657. Xfrom the list assembled by ajayshah@usc.edu.
  658. X
  659. XName: SPARSE
  660. XWhere: in sparse on Netlib
  661. XDescription: library for LU factorisation for large sparse matrices 
  662. XAuthor: Ken Kundert, Alberto Sangiovanni-Vincentelli,
  663. X     sparse@ic.berkeley.edu
  664. X
  665. XName: matrix.tar.Z
  666. XWhere: in ftp-raimund/pub/src/Math on nestroy.wu-wien.ac.at
  667. X     (137.208.3.4)
  668. XAuthor: Paul Schmidt, TI
  669. XDescription: Small matrix library, including SOR, WLS
  670. X
  671. XName: matrix04.zip
  672. XWhere: in mirrors/msdos/c on wuarchive.wustl.edu
  673. XDescription: Small matrix toolbox
  674. X
  675. XName: Matrix.tar.Z
  676. XWhere: in pub ftp.cs.ucla.edu
  677. XDescription: The C++ Matrix class, including a matrix implementation of
  678. X     the backward error propagation (backprop) algorithm for training
  679. X     multi-layer, feed-forward artificial neural networks
  680. XAuthor: E. Robert (Bob) Tisdale, edwin@cs.ucla.edu
  681. X
  682. XName: meschach
  683. XWhere: in c/meschach on netlib
  684. XSystems: Unix, PC
  685. XDescription: a library for matrix computation; more functionality than
  686. X     Linpack; nonstandard matrices
  687. XAuthor: David E. Stewart, des@thrain.anu.edu.au
  688. XVersion: 1.0, Feb 1992
  689. X
  690. XName: nlmdl
  691. XWhere: in pub/arg/nlmdl at ccvr1.cc.ncsu.edu (128.109.212.20)
  692. XLanguage: C++
  693. XSystems: Unix, MS-DOS (Turbo C++)
  694. XDescription: a library for estimation of nonlinear models
  695. XAuthor: A. Ronald Gallant, arg@ccvr1.cc.ncsu.edu
  696. XComments: nonlinear maximisation, estimation, includes a real matrix
  697. X     class
  698. XVersion: January 1991
  699. X
  700. X
  701. X
  702. X---------------------------------------------------------------------------
  703. X
  704. X
  705. XChanges
  706. X=======
  707. X
  708. XNewmat06 - December 1992:
  709. X
  710. XAdded band matrices; 'real' changed to 'Real' (to avoid potential
  711. Xconflict in complex class); Inject doesn't check for no loss of
  712. Xinformation;  fixes for AT&T C++ version 3.0; real(A) becomes
  713. XA.AsScalar(); CopyToMatrix becomes AsMatrix, etc; .c() is no longer
  714. Xrequired (to be deleted in next version); option for version 2.1 or
  715. Xlater. Suffix for include files changed to .h; BOOL changed to Boolean
  716. X(BOOL doesn't work in g++ v 2.0); modfications to allow for compilers
  717. Xthat destroy temporaries very quickly; (Gnu users - see the section of
  718. Xcompiler performance). Added CleanUp, LinearEquationSolver, primitive
  719. Xversion of exceptions.
  720. X
  721. X
  722. XNewmat05 - June 1992:
  723. X
  724. XFor private release only 
  725. X
  726. X
  727. XNewmat04 - December 1991:
  728. X
  729. XFix problem with G++1.40, some extra documentation
  730. X
  731. X
  732. XNewmat03 - November 1991:
  733. X
  734. XCol and Cols become Column and Columns. Added Sort, SVD, Jacobi,
  735. XEigenvalues, FFT, real conversion of 1x1 matrix, "Numerical Recipes in
  736. XC" interface, output operations, various scalar functions. Improved
  737. Xreturn from functions. Reorganised setting options in "include.hxx".
  738. X
  739. X
  740. XNewmat02 - July 1991:
  741. X
  742. XVersion with matrix row/column operations and numerous additional
  743. Xfunctions.
  744. X
  745. X
  746. XMatrix - October 1990:
  747. X
  748. XEarly version of package.
  749. X
  750. X
  751. X---------------------------------------------------------------------------
  752. X
  753. X
  754. XHow to get a copy of this package
  755. X=================================
  756. X
  757. XI am putting copies on Compuserve (Borland library, zip format),
  758. XSIMTEL20 (MsDos library, zip format), comp.sources.misc on Internet
  759. X(shar format).
  760. X
  761. X
  762. X---------------------------------------------------------------------------
  763. X
  764. X
  765. XCompiler performance
  766. X====================
  767. X
  768. XI have tested this package on a number of compilers. Here are the levels
  769. Xof success with this package. In most cases I have chosen code that
  770. Xworks under all the compilers I have access to, but I have had to
  771. Xinclude some specific work-arounds for some compilers. For the MsDos
  772. Xversions, I use a 486dx computer running MsDos 5. The unix versions are
  773. Xon a Sun Sparc station or a Silicon Graphics or a HP unix workstation.
  774. XThanks to Victoria University and Industrial Research Ltd for access to
  775. Xthe Unix machines.
  776. X
  777. XA series of #defines at the beginning of "include.h" customises the
  778. Xpackage for the compiler you are using. Turbo, Borland, Gnu and Zortech
  779. Xare recognised automatically, otherwise you have to set the appropriate
  780. X#define statement. Activate the option for version 2.1 if you are using
  781. Xversion 2.1 of C++ or later.
  782. X
  783. XBorland C++ 3.1: Recently, this has been my main development platform,
  784. Xso naturally almost everything works with this compiler. Make sure you
  785. Xhave the compiler option "treat enums as ints" set. There was a problem
  786. Xwith the library utility in version 2.0 which is now fixed. You will
  787. Xneed to use the large model. If you are not debugging, turn off the
  788. Xoptions that collect debugging information.
  789. X
  790. XZortech C++ 3.0: "const" doesn't work correctly with this compiler, so
  791. Xthe package skips all of the statements Zortech can't handle. Zortech
  792. Xleaves rubbish on the heap. I don't know whether this is my programming
  793. Xerror or a Zortech error or additional printer buffers. Deactivate the
  794. Xoption for version 2.1 in include.h. Does not support IO manipulators.
  795. XOtherwise the package mostly works, but not completely.
  796. X
  797. XGlockenspiel C++ (2.00a for MsDos loading into Microsoft C 5.1): I
  798. Xhaven't tested the latest version of my package with Glockenspiel. I had
  799. Xto #define the matrix names to shorter names to avoid ambiguities and
  800. Xhad quite a bit of difficulty stopping the compiles from running out of
  801. Xspace and not exceeding Microsoft's block nesting limit. A couple of my
  802. Xtest statements produced statements too complex for Microsoft, but
  803. Xbasically the package worked. This was my original development platform
  804. Xand I still use .cxx as my file name extensions for the C++ files.
  805. X
  806. XSun AT&T C++ 2.1;3.0: This works fine. Except aggregates are not
  807. Xsupported in 2.1 and setjmp.h generated a warning message. Neither
  808. Xcompiler would compile when I set DO_FREE_CHECK (see my file
  809. Xnewmatc.txt).
  810. X
  811. XGnu G++ 2.2:  This mostly works. You can't use expressions like
  812. XMatrix(X*Y) in the middle of an expression and (Matrix)(X*Y) is
  813. Xunreliable. If you write a function returning a matrix, you MUST use the
  814. XReturnMatrix method described in this documentation. This is because g++
  815. Xdestroys temporaries occuring in an expression too soon for the two
  816. Xstage way of evaluating expressions that newmat uses. Gnu 2.2 does seem
  817. Xto leave some rubbish on the stack. I suspect this is a printer buffer
  818. Xso it may not be a bug. There were a number of warning messages from the
  819. Xcompiler about my "unconstanting" constants; but I think this was just
  820. Xgnu being over-sensitive.
  821. X
  822. XJPI: Their second release worked on a previous version of this package
  823. Xprovided you disabled the smart link option - it isn't smart enough. I
  824. Xhaven't tested the latest version of this package.
  825. X
  826. X
  827. X---------------------------------------------------------------------------
  828. X
  829. XExample
  830. X=======
  831. X
  832. XAn example is given in  example.cxx .  This gives a simple linear
  833. Xregression example using four different algorithms. The correct output
  834. Xis given in example.txt. The program carries out a check that no memory
  835. Xis left allocated on the heap when it terminates. The file  example.mak
  836. Xis a make file for compiling example.cxx under gnu g++. Use the gnu make
  837. Xfacility. You can probably adapt for the compiler you are using.
  838. X
  839. X ---------------------------------------------------------------------
  840. X| Don't forget to remove references to  newmat9.cxx  in the make file |
  841. X| if you are using a compiler that does not support the standard io   |
  842. X| manipulators.                                                       |
  843. X ---------------------------------------------------------------------
  844. X
  845. X---------------------------------------------------------------------------
  846. X
  847. X
  848. XDetailed Documentation
  849. X======================
  850. X
  851. XCopyright (C) 1989,1990,1991,1992: R B Davies
  852. X
  853. XPermission is granted to use but not to sell.
  854. X
  855. X   --------------------------------------------------------------
  856. X  | Please understand that this is a test version; there may     |
  857. X  | still be bugs and errors. Use at your own risk. I take no    |
  858. X  | responsibility for any errors or omissions in this package   |
  859. X  | or for any misfortune that may befall you or others as a     |
  860. X  | result of its use.                                           |
  861. X   --------------------------------------------------------------
  862. X
  863. XPlease report bugs to me at
  864. X
  865. X    robertd@kauri.vuw.ac.nz
  866. X
  867. Xor
  868. X
  869. X    Compuserve 72777,656
  870. X
  871. XWhen reporting a bug please tell me which C++ compiler you are using (if
  872. Xknown), and what version. Also give me details of your computer (if
  873. Xknown). Tell me where you downloaded your version of my package from and
  874. Xits version number (eg newmat03 or newmat04). (There may be very minor
  875. Xdifferences between versions at different sites). Note any changes you
  876. Xhave made to my code. If at all possible give me a piece of code
  877. Xillustrating the bug.
  878. X
  879. XPlease do report bugs to me.
  880. X
  881. X
  882. XThe matrix inverse routine and the sort routines are adapted from
  883. X"Numerical Recipes in C" by Press, Flannery, Teukolsky, Vetterling,
  884. Xpublished by the Cambridge University Press.
  885. X
  886. XOther code is adapted from routines in "Handbook for Automatic
  887. XComputation, Vol II, Linear Algebra" by Wilkinson and Reinsch, published
  888. Xby Springer Verlag. 
  889. X
  890. X
  891. XCustomising
  892. X-----------
  893. X
  894. XI use .h as the suffix of definition files and .cxx as the suffix of
  895. XC++ source files. This does not cause any problems with the compilers I
  896. Xuse except that Borland and Turbo need to be told to accept any suffix
  897. Xas meaning a C++ file rather than a C file.
  898. X
  899. XUse the large model when you are using a PC. Do not "outline" inline
  900. Xfunctions.
  901. X
  902. XEach file accessing the matrix package needs to have file newmat.h 
  903. X#included  at the beginning. Files using matrix applications (Cholesky
  904. Xdecomposition, Householder triangularisation etc) need newmatap.h
  905. Xinstead (or as well). If you need the output functions you will also
  906. Xneed newmatio.h.
  907. X
  908. XThe file  include.h  sets the options for the compiler. If you are using
  909. Xa compiler different from one I have worked with you may have to set up
  910. Xa new section in  include.h  appropriate for your compiler.
  911. X
  912. XBorland, Turbo, Gnu and Zortech are recognised automatically. If you
  913. Xusing Glockenspiel on a PC, AT&T activate the appropriate statement at
  914. Xthe beginning of include.h.
  915. X
  916. XActivate the appropriate statement to make the element type float or
  917. Xdouble.
  918. X
  919. XIf you are using version 2.1 or later of C++ make sure Version21 is
  920. X#defined, otherwise make sure it is not #defined.
  921. X
  922. XThe file (newmat9.cxx) containing the output routines can be used only
  923. Xwith libraries that support the AT&T input/output routines including
  924. Xmanipulators. It cannot be used with Zortech or Gnu.
  925. X
  926. XYou will need to compile all the *.cxx files except example.cxx and the
  927. Xtmt*.cxx files to to get the complete package. The tmt*.cxx files are
  928. Xused for testing and example.cxx is an example. The files tmt.mak and
  929. Xexample.mak are "make" files for unix systems. Edit in the correct name
  930. Xof compiler. This "make" file worked for me with the default "make" on
  931. Xthe HP unix workstation and the Sun sparc station and gmake on the
  932. XSilicon Graphics. With Borland, its pretty quick just to load all the
  933. Xfiles in the interactive environment by pointing and clicking.
  934. X
  935. X
  936. XConstructors
  937. X------------
  938. X
  939. XTo construct an m x n matrix, A, (m and n are integers) use
  940. X
  941. X    Matrix A(m,n);
  942. X
  943. XThe UpperTriangularMatrix, LowerTriangularMatrix, SymmetricMatrix and
  944. XDiagonalMatrix types are square. To construct an n x n matrix use,
  945. Xfor example
  946. X
  947. X    UpperTriangularMatrix U(n);
  948. X
  949. XBand matrices need to include bandwidth information in their
  950. Xconstructors.
  951. X
  952. X    BandMatrix BM(n, lower, upper);
  953. X    UpperBandMatrix UB(n, upper);
  954. X    LowerBandMatrix LB(n, lower);
  955. X    SymmetrixBandMatrix SB(n, lower);
  956. X
  957. XThe integers upper and lower are the number of non-zero diagonals above
  958. Xand below the diagonal (excluding the diagonal) respectively.
  959. XThe RowVector and ColumnVector types take just one argument in their
  960. Xconstructors:
  961. X
  962. X    RowVector RV(n);
  963. X
  964. XYou can also construct vectors and matrices without specifying the
  965. Xdimension. For example
  966. X
  967. X    Matrix A;
  968. X
  969. XIn this case the dimension must be set by an assignment statement or a
  970. Xre-dimension statement.
  971. X
  972. XYou can also use a constructor to set a matrix equal to another matrix
  973. Xor matrix expression.
  974. X
  975. X    Matrix A = U;
  976. X
  977. X    Matrix A = U * L;
  978. X
  979. XOnly conversions that don't lose information are supported - eg you
  980. Xcannot convert an upper triangular matrix into a diagonal matrix using =.
  981. X
  982. X
  983. XElements of matrices
  984. X--------------------
  985. X
  986. XElements are accessed by expressions of the form A(i,j) where i and j
  987. Xrun from 1 to the appropriate dimension. Access elements of vectors with
  988. Xjust one argument. Diagonal matrices can accept one or two subscripts.
  989. X
  990. XThis is different from the earliest version of the package in which the
  991. Xsubscripts ran from 0 to one less than the appropriate dimension. Use
  992. XA.element(i,j) if you want this earlier convention.
  993. X
  994. XA(i,j) and A.element(i,j) can appear on either side of an = sign.
  995. X
  996. X
  997. XMatrix copy
  998. X-----------
  999. X
  1000. XThe operator = is used for copying matrices, converting matrices, or
  1001. Xevaluating expressions. For example
  1002. X
  1003. X    A = B;  A = L;  A = L * U;
  1004. X
  1005. XOnly conversions that don't lose information are supported. The
  1006. Xdimensions of the matrix on the left hand side are adjusted to those of
  1007. Xthe matrix or expression on the right hand side. Elements on the right
  1008. Xhand side which are not present on the left hand side are set to zero.
  1009. X
  1010. XThe operator << can be used in place of = where it is permissible for
  1011. Xinformation to be lost.
  1012. X
  1013. XFor example
  1014. X
  1015. X    SymmetricMatrix S; Matrix A;
  1016. X    ......
  1017. X    S << A.t() * A;
  1018. X
  1019. Xis acceptable whereas
  1020. X
  1021. X    S = A.t() * A;                            // error
  1022. X
  1023. Xwill cause a runtime error since the package does not (yet) recognise
  1024. XA.t()*A as symmetric.
  1025. X
  1026. XNote that you can not use << with constructors. For example
  1027. X
  1028. X    SymmetricMatrix S << A.t() * A;           // error
  1029. X
  1030. Xdoes not work.
  1031. X
  1032. XAlso note that << cannot be used to load values from a full matrix into
  1033. Xa band matrix, since it will be unable to determine the bandwidth of the
  1034. Xband matrix.
  1035. X
  1036. XA third copy routine is used in a similar role to =. Use
  1037. X
  1038. X    A.Inject(D);
  1039. X
  1040. Xto copy the elements of D to the corresponding elements of A but leave
  1041. Xthe elements of A unchanged if there is no corresponding element of D
  1042. X(the = operator would set them to 0). This is useful, for example, for
  1043. Xsetting the diagonal elements of a matrix without disturbing the rest of
  1044. Xthe matrix. Unlike = and <<, Inject does not reset the dimensions of A,
  1045. Xwhich must match those of D. Inject does not test for no loss of
  1046. Xinformation.
  1047. X
  1048. XYou cannot replace D by a matrix expression. The effect of Inject(D)
  1049. Xdepends on the type of D. If D is an expression it might not be obvious
  1050. Xto the user what type it would have. So I thought it best to disallow
  1051. Xexpressions.
  1052. X
  1053. XInject can be used for loading values from a regular matrix into a band
  1054. Xmatrix. (Don't forget to zero any elements of the left hand side that
  1055. Xwill not be set by the loading operation).
  1056. X
  1057. XBoth << and Inject can be used with submatrix expressions on the left
  1058. Xhand side. See the section on submatrices.
  1059. X
  1060. XTo set the elements of a matrix to a scalar use operator =
  1061. X
  1062. X    Real r; Matrix A(m,n);
  1063. X    ......
  1064. X    Matrix A(m,n); A = r;
  1065. X
  1066. XYou can load the elements of a matrix from an array:
  1067. X
  1068. X    Matrix A(3,2);
  1069. X    Real a[] = { 11,12,21,22,31,33 };
  1070. X    A << a;
  1071. X
  1072. XThis construction cannot check that the numbers of elements match
  1073. Xcorrectly. This version of << can be used with submatrices on the left
  1074. Xhand side.
  1075. X
  1076. X
  1077. XUnary operators
  1078. X---------------
  1079. X
  1080. XThe package supports unary operations
  1081. X
  1082. X    change sign of elements            -A
  1083. X    transpose                          A.t()
  1084. X    inverse (of square matrix A)       A.i()
  1085. X
  1086. X
  1087. XBinary operations
  1088. X-----------------
  1089. X
  1090. XThe package supports binary operations
  1091. X
  1092. X    matrix addition                    A+B
  1093. X    matrix subtraction                 A-B
  1094. X    matrix multiplication              A*B
  1095. X    equation solve (square matrix A)   A.i()*B
  1096. X
  1097. XIn the last case the inverse is not calculated.
  1098. X
  1099. XNotes:
  1100. X
  1101. XIf you are doing repeated multiplication. For example A*B*C, use
  1102. Xbrackets to force the order to minimize the number of operations. If C
  1103. Xis a column vector and A is not a vector, then it will usually reduce
  1104. Xthe number of operations to use A*(B*C) .
  1105. X
  1106. XThe package does not recognise B*A.i() as an equation solve. It is
  1107. Xprobably better to use (A.t().i()*B.t()).t() .
  1108. X
  1109. X
  1110. XCombination of a matrix and scalar
  1111. X----------------------------------
  1112. X
  1113. XThe following expression multiplies the elements of a matrix A by a
  1114. Xscalar f:  A * f; Likewise one can divide the elements of a matrix A by
  1115. Xa scalar f:  A / f;
  1116. X
  1117. XThe expressions  A + f and A - f add or subtract a rectangular matrix of
  1118. Xthe same dimension as A with elements equal to f to or from the matrix
  1119. XA.
  1120. X
  1121. XIn each case the matrix must be the first term in the expression.
  1122. XExpressions such  f + A  or  f * A  are not recognised.
  1123. X
  1124. X
  1125. XScalar functions of matrices
  1126. X----------------------------
  1127. X            
  1128. X    int m = A.Nrows();                    // number of rows
  1129. X    int n = A.Ncols();                    // number of columns
  1130. X    Real ssq = A.SumSquare();             // sum of squares of elements
  1131. X    Real sav = A.SumAbsoluteValue();      // sum of absolute values
  1132. X    Real mav = A.MaximumAbsoluteValue();  // maximum of absolute values
  1133. X    Real norm = A.Norm1();                // maximum of sum of absolute
  1134. X                                             values of elements of a column
  1135. X    Real norm = A.NormInfinity();         // maximum of sum of absolute
  1136. X                                             values of elements of a row
  1137. X    Real t = A.Trace();                   // trace
  1138. X    LogandSign ld = A.LogDeterminant();   // log of determinant
  1139. X    Boolean z = A.IsZero();               // test all elements zero
  1140. X    MatrixType mt = A.Type();             // type of matrix
  1141. X    Real* s = Store();                    // pointer to array of elements
  1142. X    int l = Storage();                    // length of array of elements
  1143. X
  1144. XA.LogDeterminant() returns a value of type LogandSign. If ld is of type 
  1145. XLogAndSign  use
  1146. X
  1147. X    ld.Value()    to get the value of the determinant
  1148. X    ld.Sign()     to get the sign of the determinant (values 1, 0, -1)
  1149. X    ld.LogValue() to get the log of the absolute value.
  1150. X
  1151. XA.IsZero() returns Boolean value TRUE if the matrix A has all elements
  1152. Xequal to 0.0.
  1153. X
  1154. XMatrixType mt = A.Type() returns the type of a matrix. Use (char*)mt to
  1155. Xget a string  (UT, LT, Rect, Sym, Diag, RowV, ColV, Crout, BndLU)
  1156. Xshowing the type.
  1157. X
  1158. XSumSquare(A), SumAbsoluteValue(A), MaximumAbsoluteValue(A), Trace(A),
  1159. XLogDeterminant(A), Norm1(A), NormInfinity(A)  can be used in place of
  1160. XA.SumSquare(), A.SumAbsoluteValue(), A.MaximumAbsoluteValue(),
  1161. XA.Trace(), A.LogDeterminant(), A.Norm1(), A.NormInfinity().
  1162. X
  1163. X
  1164. XSubmatrix operations
  1165. X--------------------
  1166. X
  1167. XA.SubMatrix(fr,lr,fc,lc)
  1168. X
  1169. XThis selects a submatrix from A. the arguments  fr,lr,fc,lc  are the
  1170. Xfirst row, last row, first column, last column of the submatrix with the
  1171. Xnumbering beginning at 1. This may be used in any matrix expression or
  1172. Xon the left hand side of << or Inject. Inject does not check no
  1173. Xinformation loss. You can also use the construction
  1174. X
  1175. X    Real c; .... A.SubMatrix(fr,lr,fc,lc) << c;
  1176. X
  1177. Xto set a submatrix equal to a constant.
  1178. X
  1179. XThe follwing are variants of SubMatrix:
  1180. X
  1181. X    A.SymSubMatrix(f,l)             //   This assumes fr=fc and lr=lc.
  1182. X    A.Rows(f,l)                     //   select rows
  1183. X    A.Row(f)                        //   select single row
  1184. X    A.Columns(f,l)                  //   select columns
  1185. X    A.Column(f)                     //   select single column
  1186. X
  1187. XIn each case f and l mean the first and last row or column to be
  1188. Xselected (starting at 1).
  1189. X
  1190. XIf SubMatrix or its variant occurs on the right hand side of an = or <<
  1191. Xor within an expression its type is as follows
  1192. X
  1193. X    A.Submatrix(fr,lr,fc,lc):           If A is RowVector or
  1194. X                                        ColumnVector then same type
  1195. X                                        otherwise type Matrix
  1196. X    A.SymSubMatrix(f,l):                Same type as A
  1197. X    A.Rows(f,l):                        Type Matrix
  1198. X    A.Row(f):                           Type RowVector
  1199. X    A.Columns(f,l):                     Type Matrix
  1200. X    A.Column(f):                        Type ColumnVector
  1201. X
  1202. X
  1203. XIf SubMatrix or its variant appears on the left hand side of  << , think
  1204. Xof its type being Matrix. Thus L.Row(1) where L is LowerTriangularMatrix
  1205. Xexpects  L.Ncols()  elements even though it will use only one of them.
  1206. X
  1207. X
  1208. XChange dimensions
  1209. X-----------------
  1210. X
  1211. XThe following operations change the dimensions of a matrix. The values
  1212. Xof the elements are lost.
  1213. X
  1214. X    A.ReDimension(nrows,ncols);     // for type Matrix or nricMatrix
  1215. X    A.ReDimension(n);               // for all other types, except Band
  1216. X    A.ReDimension(n,lower,upper);   // for BandMatrix
  1217. X    A.ReDimension(n,lower);         // for LowerBandMatrix
  1218. X    A.ReDimension(n,upper);         // for UpperBandMatrix
  1219. X    A.ReDimension(n,lower);         // for SymmetricBandMatrix
  1220. X
  1221. XUse   A.CleanUp()  to set the dimensions of A to zero and release all
  1222. Xthe heap memory.
  1223. X
  1224. X
  1225. XChange type
  1226. X-----------
  1227. X
  1228. XThe following functions interpret the elements of a matrix
  1229. X(stored row by row) to be a vector or matrix of a different type. Actual
  1230. Xcopying is usually avoided where these occur as part of a more
  1231. Xcomplicated expression.
  1232. X
  1233. X    A.AsRow()
  1234. X    A.AsColumn()
  1235. X    A.AsDiagonal()
  1236. X    A.AsMatrix(nrows,ncols)
  1237. X    A.AsScalar()
  1238. X
  1239. XThe expression A.AsScalar() is used to convert a 1 x 1 matrix to a
  1240. Xscalar.
  1241. X
  1242. X
  1243. XMultiple matrix solve
  1244. X---------------------
  1245. X
  1246. XIf A is a square or symmetric matrix use
  1247. X
  1248. X    CroutMatrix X = A;                // carries out LU decomposition
  1249. X    Matrix AP = X.i()*P; Matrix AQ = X.i()*Q;
  1250. X    LogAndSign ld = X.LogDeterminant();
  1251. X
  1252. Xrather than
  1253. X
  1254. X    Matrix AP = A.i()*P; Matrix AQ = A.i()*Q;
  1255. X    LogAndSign ld = A.LogDeterminant();
  1256. X
  1257. Xsince each operation will repeat the LU decomposition.
  1258. X
  1259. XIf A is a BandMatrix or a SymmetricBandMatrix begin with
  1260. X
  1261. X    BandLUMatrix X = A;               // carries out LU decomposition
  1262. X
  1263. XA CroutMatrix or a BandLUMatrix can't be manipulated or copied. Use
  1264. Xreferences as an alternative to copying.
  1265. X
  1266. XAlternatively use
  1267. X
  1268. X    LinearEquationSolver X = A;
  1269. X
  1270. XThis will choose the most appropiate decomposition of A. That is, the
  1271. Xband form if A is banded; the Crout decomposition if A is square or
  1272. Xsymmetric and no decomposition if A is triangular or diagonal. If you
  1273. Xwant to use the LinearEquationSolver #include newmatap.h.
  1274. X
  1275. X
  1276. XMemory management
  1277. X-----------------
  1278. X
  1279. XThe package does not support delayed copy. Several strategies are
  1280. Xrequired to prevent unnecessary matrix copies.
  1281. X
  1282. XWhere a matrix is called as a function argument use a constant
  1283. Xreference. For example
  1284. X
  1285. X    YourFunction(const Matrix& A)
  1286. X
  1287. Xrather than
  1288. X
  1289. X    YourFunction(Matrix A)
  1290. X
  1291. X
  1292. XSkip the rest of this section on your first reading.
  1293. X
  1294. X --------------------------------------------------------------------- 
  1295. X|  Gnu g++ users please read on; if you are returning matrix values   |
  1296. X|  from a function, then you must use the ReturnMatrix construct.     |
  1297. X ---------------------------------------------------------------------
  1298. X
  1299. XA second place where it is desirable to avoid unnecessary copies is when
  1300. Xa function is returning a matrix. Matrices can be returned from a
  1301. Xfunction with the return command as you would expect. However these may
  1302. Xincur one and possibly two copyings of the matrix. To avoid this use the
  1303. Xfollowing instructions.
  1304. X
  1305. XMake your function of type  ReturnMatrix . Then precede the return
  1306. Xstatement with a Release statement (or a ReleaseAndDelete statement if
  1307. Xthe matrix was created with new). For example
  1308. X
  1309. X
  1310. X    ReturnMatrix MakeAMatrix()
  1311. X    {
  1312. X       Matrix A;
  1313. X       ......
  1314. X       A.Release(); return A;
  1315. X    }
  1316. X
  1317. Xor
  1318. X
  1319. X    ReturnMatrix MakeAMatrix()
  1320. X    {
  1321. X       Matrix* m = new Matrix;
  1322. X       ......
  1323. X       m->ReleaseAndDelete(); return *m;
  1324. X    }
  1325. X
  1326. X
  1327. XIf you are using AT&T C++ you may wish to replace  return A; by
  1328. Xreturn (ReturnMatrix)A;  to avoid a warning message.
  1329. X
  1330. X --------------------------------------------------------------------- 
  1331. X| Do not forget to make the function of type ReturnMatrix; otherwise  |
  1332. X| you may get incomprehensible run-time errors.                       |
  1333. X --------------------------------------------------------------------- 
  1334. X
  1335. XYou can also use .Release() or ->ReleaseAndDelete() to allow a matrix
  1336. Xexpression to recycle space. Suppose you call
  1337. X
  1338. X    A.Release();
  1339. X
  1340. Xjust before A is used just once in an expression. Then the memory used
  1341. Xby A is either returned to the system or reused in the expression. In
  1342. Xeither case, A's memory is destroyed. This procedure can be used to
  1343. Ximprove efficiency and reduce the use of memory.
  1344. X
  1345. XUse ->ReleaseAndDelete for matrices created by new if you want to
  1346. Xcompletely delete the matrix after it is accessed.
  1347. X
  1348. X
  1349. XOutput
  1350. X------
  1351. X
  1352. XTo print a matrix use an expression like
  1353. X
  1354. X    Matrix A;
  1355. X    ......
  1356. X    cout << setw(10) << setprecision(5) << A;
  1357. X
  1358. XThis will work only with systems that support the AT&T input/output
  1359. Xroutines including manipulators.
  1360. X
  1361. X
  1362. XAccessing matrices of unspecified type
  1363. X--------------------------------------
  1364. X
  1365. XSkip this section on your first reading.
  1366. X
  1367. XSuppose you wish to write a function which accesses a matrix of unknown
  1368. Xtype including expressions (eg A*B). Then use a layout similar to the
  1369. Xfollowing:
  1370. X
  1371. X   void YourFunction(BaseMatrix& X)
  1372. X   {
  1373. X      GeneralMatrix* gm = X.Evaluate();   // evaluate an expression
  1374. X                                          // if necessary
  1375. X      ........                            // operations on *gm
  1376. X      gm->tDelete();                      // delete *gm if a temporary
  1377. X   }
  1378. X
  1379. XSee, as an example, the definitions of operator<< in newmat9.cxx.
  1380. X
  1381. XUnder certain circumstances; particularly where X is to be used just
  1382. Xonce in an expression you can leave out the Evaluate() statement and the
  1383. Xcorresponding tDelete(). Just use X in the expression.
  1384. X
  1385. XIf you know YourFunction will never have to handle a formula as its
  1386. Xargument you could also use
  1387. X
  1388. X   void YourFunction(const GeneralMatrix& X)
  1389. X   {
  1390. X      ........                            // operations on X
  1391. X   }
  1392. X
  1393. X
  1394. XCholesky decomposition
  1395. X----------------------
  1396. X
  1397. XSuppose S is symmetric and positive definite. Then there exists a unique
  1398. Xlower triangular matrix L such that L * L.t() = S. To calculate this use
  1399. X
  1400. X    SymmetricMatrix S;
  1401. X    ......
  1402. X    LowerTriangularMatrix L = Cholesky(S);
  1403. X
  1404. XIf S is a symmetric band matrix then L is a band matrix and an
  1405. Xalternative procedure is provied for carrying out the decomposition:
  1406. X
  1407. X    SymmetricBandMatrix S;
  1408. X    ......
  1409. X    LowerBandMatrix L = Cholesky(S);
  1410. X
  1411. X
  1412. XHouseholder triangularisation
  1413. X-----------------------------
  1414. X
  1415. XStart with matrix
  1416. X
  1417. X       / X    0 \      s
  1418. X       \ Y    0 /      t
  1419. X
  1420. X         n    s
  1421. X
  1422. XThe Householder triangularisation post multiplies by an orthogonal
  1423. Xmatrix Q such that the matrix becomes
  1424. X
  1425. X       / 0    L \      s
  1426. X       \ Z    M /      t
  1427. X
  1428. X         n    s
  1429. X
  1430. Xwhere L is lower triangular. Note that X is the transpose of the matrix
  1431. Xsometimes considered in this context.
  1432. X
  1433. XThis is good for solving least squares problems: choose b (matrix or row
  1434. Xvector) to minimize the sum of the squares of the elements of
  1435. X
  1436. X         Y - b*X
  1437. X
  1438. XThen choose b = M * L.i();
  1439. X
  1440. XTwo routines are provided:
  1441. X
  1442. X    HHDecompose(X, L);
  1443. X
  1444. Xreplaces X by orthogonal columns and forms L.
  1445. X
  1446. X    HHDecompose(X, Y, M);
  1447. X
  1448. Xuses X from the first routine, replaces Y by Z and forms M.
  1449. X
  1450. X
  1451. XSingular Value Decomposition
  1452. X----------------------------
  1453. X
  1454. XThe singular value decomposition of an m x n matrix A ( where m >= n) is
  1455. Xa decomposition
  1456. X
  1457. X    A  = U * D * V.t()
  1458. X
  1459. Xwhere U is m x n with  U.t() * U  equalling the identity, D is an n x n
  1460. Xdiagonal matrix and V is an n x n orthogonal matrix.
  1461. X
  1462. XSingular value decompositions are useful for understanding the structure
  1463. Xof ill-conditioned matrices, solving least squares problems, and for
  1464. Xfinding the eigenvalues of A.t() * A.
  1465. X
  1466. XTo calculate the singular value decomposition of A (with m >= n) use one
  1467. Xof
  1468. X
  1469. X    SVD(A, D, U, V);                  // U (= A is OK)
  1470. X    SVD(A, D);
  1471. X    SVD(A, D, U);                     // U (= A is OK)
  1472. X    SVD(A, D, U, FALSE);              // U (can = A) for workspace only
  1473. X    SVD(A, D, U, V, FALSE);           // U (can = A) for workspace only
  1474. X
  1475. XThe values of A are not changed unless A is also inserted as the third
  1476. Xargument.
  1477. X
  1478. X
  1479. XEigenvalues
  1480. X-----------
  1481. X
  1482. XAn eigenvalue decomposition of a symmetric matrix A is a decomposition
  1483. X
  1484. X    A  = V * D * V.t()
  1485. X
  1486. Xwhere V is an orthogonal matrix and D is a diagonal matrix.
  1487. X
  1488. XEigenvalue analyses are used in a wide variety of engineering,
  1489. Xstatistical and other mathematical analyses.
  1490. X
  1491. XThe package includes two algorithms: Jacobi and Householder. The first
  1492. Xis extremely reliable but much slower than the second.
  1493. X
  1494. XThe code is adapted from routines in "Handbook for Automatic
  1495. XComputation, Vol II, Linear Algebra" by Wilkinson and Reinsch, published
  1496. Xby Springer Verlag. 
  1497. X
  1498. X
  1499. X    Jacobi(A,D,S,V);                  // A, S symmetric; S is workspace,
  1500. X                                      //    S = A is OK
  1501. X    Jacobi(A,D);                      // A symmetric
  1502. X    Jacobi(A,D,S);                    // A, S symmetric; S is workspace,
  1503. X                                      //    S = A is OK
  1504. X    Jacobi(A,D,V);                    // A symmetric
  1505. X
  1506. X    EigenValues(A,D);                 // A symmetric
  1507. X    EigenValues(A,D,S);               // A, S symmetric; S is for back
  1508. X                                      //    transforming, S = A is OK
  1509. X    EigenValues(A,D,V);               // A symmetric
  1510. X
  1511. X
  1512. XSorting
  1513. X-------
  1514. X
  1515. XTo sort the values in a matrix or vector, A, (in general this operation
  1516. Xmakes sense only for vectors and diagonal matrices) use
  1517. X
  1518. X    SortAscending(A);
  1519. X
  1520. Xor
  1521. X
  1522. X    SortDescending(A);
  1523. X
  1524. XI use the Shell-sort algorithm. This is a medium speed algorithm, you
  1525. Xmight want to replace it with something faster if speed is critical and
  1526. Xyour matrices are large.
  1527. X
  1528. X
  1529. XFast Fourier Transform
  1530. X----------------------
  1531. X
  1532. XFFT(CV1, CV2, CV3, CV4);       // CV3=CV1 and CV4=CV2 is OK
  1533. X
  1534. Xwhere CV1, CV2, CV3, CV4 are column vectors. CV1 and CV2 are the real
  1535. Xand imaginary input vectors; CV3 and CV4 are the real and imaginary
  1536. Xoutput vectors. The lengths of CV1 and CV2 must be equal and should be
  1537. Xthe product of numbers less than about 10 for fast execution.
  1538. X
  1539. X
  1540. XInterface to Numerical Recipes in C
  1541. X-----------------------------------
  1542. X
  1543. XThis package can be used with the vectors and matrices defined in
  1544. X"Numerical Recipes in C". You need to edit the routines in Numerical
  1545. XRecipes so that the elements are of the same type as used in this
  1546. Xpackage. Eg replace float by double, vector by dvector and matrix by
  1547. Xdmatrix, etc. You will also need to edit the function definitions to use
  1548. Xthe version acceptable to your compiler. Then enclose the code from
  1549. XNumerical Recipes in  extern "C" { ... }. You will also need to include
  1550. Xthe matrix and vector utility routines.
  1551. X
  1552. XThen any vector in Numerical Recipes with subscripts starting from 1 in
  1553. Xa function call can be accessed by a RowVector, ColumnVector or
  1554. XDiagonalMatrix in the present package. Similarly any matrix with
  1555. Xsubscripts starting from 1 can be accessed by an  nricMatrix  in the
  1556. Xpresent package. The class nricMatrix is derived from Matrix and can be
  1557. Xused in place of Matrix. In each case, if you wish to refer to a
  1558. XRowVector, ColumnVector, DiagonalMatrix or nricMatrix X in an function
  1559. Xfrom Numerical Recipes, use X.nric() in the function call.
  1560. X
  1561. XNumerical Recipes cannot change the dimensions of a matrix or vector. So
  1562. Xmatrices or vectors must be correctly dimensioned before a Numerical
  1563. XRecipes routine is called.
  1564. X
  1565. XFor example
  1566. X
  1567. X   SymmetricMatrix B(44);
  1568. X   .....                             // load values into B
  1569. X   nricMatrix BX = B;                // copy values to an nricMatrix
  1570. X   DiagonalMatrix D(44);             // Matrices for output
  1571. X   nricMatrix V(44,44);              //    correctly dimensioned
  1572. X   int nrot;
  1573. X   jacobi(BX.nric(),44,D.nric(),V.nric(),&nrot);
  1574. X                                     // jacobi from NRIC
  1575. X   cout << D;                        // print eigenvalues
  1576. X
  1577. X
  1578. XExceptions
  1579. X----------
  1580. X
  1581. XThis package includes a partial implementation of exceptions. I used
  1582. XCarlos Vidal's article in the September 1992 C Users Journal as a
  1583. Xstarting point.
  1584. X
  1585. XNewmat does a partial clean up of memory following throwing an exception
  1586. X- see the next section. However, the present version will leave a little
  1587. Xheap memory unrecovered under some circumstances. I would not expect
  1588. Xthis to be a problem in most circumstances, but it is something that
  1589. Xneeds to be sorted out.
  1590. X
  1591. XThe functions/macros I define are Try, Throw, Catch, CatchAll and
  1592. XCatchAndThrow. Try, Throw, Catch and CatchAll correspond to try, throw,
  1593. Xcatch and catch(...) in the C++ standard. A list of Catch clauses must
  1594. Xbe terminated by either CatchAll or CatchAndThrow but not both. Throw
  1595. Xtakes an Exception as an argument or takes no argument (for passing on
  1596. Xan exception). I do not have a version of Throw for specifying which
  1597. Xexceptions a function might throw. Catch takes an exception class name
  1598. Xas an argument; CatchAll and CatchAndThrow don't have any arguments.
  1599. XTry, Catch and CatchAll must be followed by blocks enclosed in curly
  1600. Xbrackets.
  1601. X
  1602. XAll Exceptions must be derived from a class, Exception, defined in
  1603. Xnewmat and can contain only static variables. See the examples in newmat
  1604. Xif you want to define additional exceptions.
  1605. X
  1606. XI have defined 5 clases of exceptions for users (there are others but I
  1607. Xsuggest you stick to these ones):
  1608. X
  1609. X   SpaceException                 Insufficient space on the heap
  1610. X   ProgramException               Errors such as out of range index or
  1611. X                                  incompatible matrix types or
  1612. X                                  dimensions
  1613. X   ConvergenceException           Iterative process does not converge
  1614. X   DataException                  Errors such as attempting to invert a
  1615. X                                  singular matrix
  1616. X   InternalException              Probably a programming error in newmat
  1617. X
  1618. XFor each of these exception classes, I have defined a member function
  1619. Xvoid SetAction(int). If you call SetAction(1), and a corresponding
  1620. Xexception occurs, you will get an error message. If there is a Catch
  1621. Xclause for that exception, execution will be passed to that clause,
  1622. Xotherwise the program will exit. If you call SetAction(0) you will get
  1623. Xthe same response, except that there will be no error message. If you
  1624. Xcall SetAction(-1), you will get the error message but the program will
  1625. Xalways exit.
  1626. X
  1627. XI have defined a class Tracer that is intended to help locate the place
  1628. Xwhere an error has occurred. At the beginning of a function I suggest
  1629. Xyou include a statement like
  1630. X
  1631. X   Tracer tr("name");
  1632. X
  1633. Xwhere name is the name of the function. This name will be printed as
  1634. Xpart of the error message, if an exception occurs in that function, or
  1635. Xin a function called from that function. You can change the name as you
  1636. Xproceed through a function with the ReName function
  1637. X
  1638. X   tr.ReName("new name");
  1639. X
  1640. Xif, for example, you want to track progress through the function.
  1641. X
  1642. X
  1643. XClean up following an exception
  1644. X-------------------------------
  1645. X
  1646. XThe exception mechanisms in newmat are based on the C functions setjmp
  1647. Xand longjmp. These functions do not call destructors so can lead to
  1648. Xgarbage being left on the heap. (I refer to memory allocated by "new" as
  1649. Xheap memory). For example, when you call
  1650. X
  1651. XMatrix A(20,30);
  1652. X
  1653. Xa small amount of space is used on the stack containing the row and
  1654. Xcolumn dimensions of the matrix and 600 doubles are allocated on the
  1655. Xheap for the actual values of the matrix. At the end of the block in
  1656. Xwhich A is declared, the destructor for A is called and the 600
  1657. Xdoubles are freed. The locations on the stack are freed as part of the
  1658. Xnormal operations of the stack. If you leave the block using a longjmp
  1659. Xcommand those 600 doubles will not be freed and will occupy space until
  1660. Xthe program terminates.
  1661. X
  1662. XTo overcome this problem newmat keeps a list of all the currently
  1663. Xdeclared matrices and its exception mechanism will return heap memory
  1664. Xwhen you do a Throw and Catch.
  1665. X
  1666. XHowever it will not return heap memory from objects from other packages.
  1667. XIf you want the mechanism to work with another class you will have to do
  1668. Xthree things:
  1669. X
  1670. X1: derive your class from class Janitor defined in except.h;
  1671. X
  1672. X2: define a function void CleanUp() in that class to return all heap
  1673. X   memory;
  1674. X
  1675. X3: include the following lines in the class definition
  1676. X
  1677. X      public:
  1678. X         void* operator new(size_t size)
  1679. X         { do_not_link=TRUE; void* t = ::operator new(size); return t; }
  1680. X
  1681. X
  1682. X
  1683. X
  1684. X
  1685. X
  1686. X---------------------------------------------------------------------------
  1687. X
  1688. X
  1689. XList of files
  1690. X=============
  1691. X
  1692. XREADME          readme file
  1693. XNEWMATA  TXT    documentation file
  1694. XNEWMATB  TXT    notes on the package design
  1695. XNEWMATC  TXT    notes on testing the package
  1696. X
  1697. XBOOLEAN  H      boolean class definition
  1698. XCONTROLW H      control word definition file
  1699. XEXCEPT   H      general exception handler definitions
  1700. XINCLUDE  H      details of include files and options
  1701. XNEWMAT   H      main matrix class definition file
  1702. XNEWMATAP H      applications definition file
  1703. XNEWMATIO H      input/output definition file
  1704. XNEWMATRC H      row/column functions definition files
  1705. XNEWMATRM H      rectangular matrix access definition files
  1706. XPRECISIO H      numerical precision constants
  1707. X
  1708. XBANDMAT  CXX    band matrix routines
  1709. XCHOLESKY CXX    Cholesky decomposition
  1710. XERROR    CXX    general error handler
  1711. XEVALUE   CXX    eigenvalues and eigenvector calculation
  1712. XFFT      CXX    fast Fourier transform
  1713. XHHOLDER  CXX    Householder triangularisation
  1714. XJACOBI   CXX    eigenvalues by the Jacobi method
  1715. XNEWMAT1  CXX    type manipulation routines
  1716. XNEWMAT2  CXX    row and column manipulation functions
  1717. XNEWMAT3  CXX    row and column access functions
  1718. XNEWMAT4  CXX    constructors, redimension, utilities
  1719. XNEWMAT5  CXX    transpose, evaluate, matrix functions
  1720. XNEWMAT6  CXX    operators, element access
  1721. XNEWMAT7  CXX    invert, solve, binary operations
  1722. XNEWMAT8  CXX    LU decomposition, scalar functions
  1723. XNEWMAT9  CXX    output routines
  1724. XNEWMATEX CXX    matrix exception handler
  1725. XNEWMATRM CXX    rectangular matrix access functions
  1726. XSORT     CXX    sorting functions
  1727. XSUBMAT   CXX    submatrix functions
  1728. XSVD      CXX    singular value decomposition
  1729. X
  1730. XEXAMPLE  CXX    example of use of package
  1731. XEXAMPLE  TXT    output from example
  1732. XEXAMPLE  MAK    make file for example
  1733. X
  1734. X---------------------------------------------------------------------------
  1735. X
  1736. X                   Matrix package problem report form
  1737. X                   ----------------------------------
  1738. X
  1739. XVersion: ...............newmat06
  1740. XDate of release: .......December 1st, 1992
  1741. XPrimary site: ..........
  1742. XDownloaded from: .......
  1743. XYour email address: ....
  1744. XToday's date: ..........
  1745. XYour machine: ..........
  1746. XOperating system: ......
  1747. XCompiler & version: ....
  1748. XDescribe the problem - attach examples if possible:
  1749. X
  1750. X
  1751. X
  1752. X
  1753. X
  1754. X
  1755. X
  1756. X
  1757. X
  1758. XEmail to  robertd@kauri.vuw.ac.nz  or  Compuserve 72777,656 
  1759. X
  1760. X-------------------------------------------------------------------------------
  1761. END_OF_FILE
  1762. if test 42666 -ne `wc -c <'newmata.txt'`; then
  1763.     echo shar: \"'newmata.txt'\" unpacked with wrong size!
  1764. fi
  1765. # end of 'newmata.txt'
  1766. fi
  1767. if test -f 'readme' -a "${1}" != "-c" ; then 
  1768.   echo shar: Will not clobber existing file \"'readme'\"
  1769. else
  1770. echo shar: Extracting \"'readme'\" \(504 characters\)
  1771. sed "s/^X//" >'readme' <<'END_OF_FILE'
  1772. X   ReadMe file for newmat06, an experimental matrix package in C++.
  1773. X
  1774. X
  1775. XDocumentation is in  newmata.txt, newmatb.txt and newmatc.txt.
  1776. X
  1777. X
  1778. XIf you are upgrading from newmat03 or newmat04 note the following
  1779. X
  1780. X.hxx files are now .h files
  1781. X
  1782. Xreal changed to Real
  1783. X
  1784. XBOOL changed to Boolean
  1785. X
  1786. XCopyToMatrix changed to AsMatrix, etc
  1787. X
  1788. Xreal(A) changed to A.AsScalar()
  1789. X
  1790. Xoption added in include.h for version 2.1 or later
  1791. X
  1792. Xadded band matrices
  1793. X
  1794. Xadded exceptions.
  1795. X
  1796. X
  1797. XSee the section on changes in newmata.txt for other changes.
  1798. END_OF_FILE
  1799. if test 504 -ne `wc -c <'readme'`; then
  1800.     echo shar: \"'readme'\" unpacked with wrong size!
  1801. fi
  1802. # end of 'readme'
  1803. fi
  1804. echo shar: End of archive 1 \(of 7\).
  1805. cp /dev/null ark1isdone
  1806. MISSING=""
  1807. for I in 1 2 3 4 5 6 7 ; do
  1808.     if test ! -f ark${I}isdone ; then
  1809.     MISSING="${MISSING} ${I}"
  1810.     fi
  1811. done
  1812. if test "${MISSING}" = "" ; then
  1813.     echo You have unpacked all 7 archives.
  1814.     rm -f ark[1-9]isdone
  1815. else
  1816.     echo You still need to unpack the following archives:
  1817.     echo "        " ${MISSING}
  1818. fi
  1819. ##  End of shell archive.
  1820. exit 0
  1821.  
  1822. exit 0 # Just in case...
  1823.