home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / newmat07 / part01 < prev    next >
Encoding:
Text File  |  1993-01-10  |  62.3 KB  |  1,786 lines

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