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

  1. Newsgroups: comp.sources.misc
  2. From: robertd@kauri.vuw.ac.nz (Robert Davies)
  3. Subject: v34i112:  newmat07 - A matrix package in C++, Part06/08
  4. Message-ID: <1993Jan11.153248.2533@sparky.imd.sterling.com>
  5. X-Md4-Signature: 3f21ed05a8e3831ba649693a88b9a6be
  6. Date: Mon, 11 Jan 1993 15:32:48 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 112
  11. Archive-name: newmat07/part06
  12. Environment: C++
  13. Supersedes: newmat06: Volume 34, Issue 7-13
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 6 (of 8)."
  22. # Contents:  bandmat.cxx cholesky.cxx evalue.cxx example.txt except.cxx
  23. #   fft.cxx hholder.cxx jacobi.cxx sort.cxx submat.cxx svd.cxx
  24. # Wrapped by robert@kea on Sun Jan 10 23:58:19 1993
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'bandmat.cxx' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'bandmat.cxx'\"
  28. else
  29. echo shar: Extracting \"'bandmat.cxx'\" \(10343 characters\)
  30. sed "s/^X//" >'bandmat.cxx' <<'END_OF_FILE'
  31. X//$$ bandmat.cxx                     Band matrix definitions
  32. X
  33. X// Copyright (C) 1991,2,3: R B Davies
  34. X
  35. X#define WANT_MATH                    // include.h will get math fns
  36. X
  37. X#include "include.h"
  38. X
  39. X#include "newmat.h"
  40. X#include "newmatrc.h"
  41. X
  42. X//#define REPORT { static ExeCounter ExeCount(__LINE__,4); ++ExeCount; }
  43. X
  44. X#define REPORT {}
  45. X
  46. X//#define REPORT1 { static ExeCounter ExeCount(__LINE__,4); ExeCount++; }
  47. X
  48. X// REPORT1 constructors only - doesn't work in turbo and Borland C++
  49. X
  50. X#define REPORT1 {}
  51. X
  52. X//#define MONITOR(what,storage,store) \
  53. X//   { cout << what << " " << storage << " at " << (long)store << "\n"; }
  54. X
  55. X#define MONITOR(what,store,storage) {}
  56. X
  57. XBandMatrix::BandMatrix(const BaseMatrix& M)
  58. X{
  59. X   REPORT1 // CheckConversion(M);
  60. X   MatrixConversionCheck mcc;
  61. X   GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::BM);
  62. X   GetMatrix(gmx); CornerClear();
  63. X}
  64. X
  65. Xvoid BandMatrix::SetParameters(const GeneralMatrix* gmx)
  66. X{
  67. X   MatrixBandWidth bw = gmx->BandWidth();
  68. X   lower = bw.lower; upper = bw.upper;
  69. X}
  70. X
  71. Xvoid BandMatrix::ReDimension(int n, int lb, int ub)
  72. X{
  73. X   REPORT
  74. X   Tracer tr("BandMatrix::ReDimension");
  75. X   if (lb<0 || ub<0) Throw(ProgramException("Undefined bandwidth"));
  76. X   lower = (lb<=n) ? lb : n-1; upper = (ub<=n) ? ub : n-1;
  77. X   GeneralMatrix::ReDimension(n,n,n*(lower+1+upper)); CornerClear();
  78. X}
  79. X
  80. Xvoid BandMatrix::operator=(const BaseMatrix& X)
  81. X{
  82. X   REPORT // CheckConversion(X);
  83. X   MatrixConversionCheck mcc;
  84. X   Eq(X,MatrixType::BM); CornerClear();
  85. X}
  86. X
  87. Xvoid BandMatrix::CornerClear() const
  88. X{
  89. X   // set unused parts of BandMatrix to zero
  90. X   REPORT
  91. X   int i = lower; Real* s = store; int bw = lower + 1 + upper;
  92. X   while (i)
  93. X      { int j = i--; Real* sj = s; s += bw; while (j--) *sj++ = 0.0; }
  94. X   i = upper; s = store + storage;
  95. X   while (i)
  96. X      { int j = i--; Real* sj = s; s -= bw; while (j--) *(--sj) = 0.0; }
  97. X}
  98. X
  99. XMatrixBandWidth MatrixBandWidth::operator+(const MatrixBandWidth& bw) const
  100. X{
  101. X   int l = bw.lower; int u = bw.upper;
  102. X   l = (lower < 0 || l < 0) ? -1 : (lower > l) ? lower : l;
  103. X   u = (upper < 0 || u < 0) ? -1 : (upper > u) ? upper : u;
  104. X   return MatrixBandWidth(l,u);
  105. X}
  106. X
  107. XMatrixBandWidth MatrixBandWidth::operator*(const MatrixBandWidth& bw) const
  108. X{
  109. X   int l = bw.lower; int u = bw.upper;
  110. X   l = (lower < 0 || l < 0) ? -1 : lower+l;
  111. X   u = (upper < 0 || u < 0) ? -1 : upper+u;
  112. X   return MatrixBandWidth(l,u);
  113. X}
  114. X
  115. XUpperBandMatrix::UpperBandMatrix(const BaseMatrix& M)
  116. X{
  117. X   REPORT1 // CheckConversion(M);
  118. X   MatrixConversionCheck mcc;
  119. X   GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::UB);
  120. X   GetMatrix(gmx); CornerClear();
  121. X}
  122. X
  123. Xvoid UpperBandMatrix::operator=(const BaseMatrix& X)
  124. X{
  125. X   REPORT // CheckConversion(X);
  126. X   MatrixConversionCheck mcc;
  127. X   Eq(X,MatrixType::UB); CornerClear();
  128. X}
  129. X
  130. XLowerBandMatrix::LowerBandMatrix(const BaseMatrix& M)
  131. X{
  132. X   REPORT1 // CheckConversion(M);
  133. X   MatrixConversionCheck mcc;
  134. X   GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::LB);
  135. X   GetMatrix(gmx); CornerClear();
  136. X}
  137. X
  138. Xvoid LowerBandMatrix::operator=(const BaseMatrix& X)
  139. X{
  140. X   REPORT // CheckConversion(X);
  141. X   MatrixConversionCheck mcc;
  142. X   Eq(X,MatrixType::LB); CornerClear();
  143. X}
  144. X
  145. XBandLUMatrix::BandLUMatrix(const BaseMatrix& m)
  146. X{
  147. X   REPORT1
  148. X   Tracer tr("BandLUMatrix");
  149. X   GeneralMatrix* gm = ((BaseMatrix&)m).Evaluate(MatrixType::BM);
  150. X   GetMatrix(gm);
  151. X   m1 = ((BandMatrix*)gm)->lower; m2 = ((BandMatrix*)gm)->upper;
  152. X   if (nrows!=ncols) Throw(NotSquareException(*this));
  153. X   d = TRUE; sing = FALSE;
  154. X   indx = new int [nrows]; MatrixErrorNoSpace(indx);
  155. X   MONITOR_INT_NEW("Index (BndLUMat)",nrows,indx)
  156. X   storage2 = nrows * m1;
  157. X   store2 = new Real [storage2]; MatrixErrorNoSpace(store2);
  158. X   MONITOR_REAL_NEW("Make (BandLUMat)",storage2,store2)
  159. X   ludcmp();
  160. X}
  161. X
  162. XBandLUMatrix::~BandLUMatrix()
  163. X{
  164. X   MONITOR_INT_DELETE("Index (BndLUMat)",nrows,indx)
  165. X   MONITOR_REAL_DELETE("Delete (BndLUMt)",storage2,store2)
  166. X#ifdef Version21
  167. X   delete [] indx; delete [] store2;
  168. X#else
  169. X   delete [nrows] indx; delete [storage2] store2;
  170. X#endif
  171. X}
  172. X
  173. XMatrixType BandLUMatrix::Type() const { return MatrixType::BC; }
  174. X
  175. X
  176. XLogAndSign BandLUMatrix::LogDeterminant() const
  177. X{
  178. X   if (sing) return 0.0;
  179. X   Real* a = store; int w = m1+1+m2; LogAndSign sum; int i = nrows;
  180. X   while (i--) { sum *= *a; a += w; }
  181. X   if (!d) sum.ChangeSign(); return sum;
  182. X}
  183. X
  184. XGeneralMatrix* BandMatrix::MakeSolver()
  185. X{
  186. X   REPORT
  187. X   GeneralMatrix* gm = new BandLUMatrix(*this);
  188. X   MatrixErrorNoSpace(gm); gm->ReleaseAndDelete(); return gm;
  189. X}
  190. X
  191. X
  192. Xvoid BandLUMatrix::ludcmp()
  193. X{
  194. X   REPORT
  195. X   Real* a = store;
  196. X   int i = m1; int j = m2; int k; int n = nrows; int w = m1 + 1 + m2;
  197. X   while (i)
  198. X   {
  199. X      Real* ai = a + i;
  200. X      k = ++j; while (k--) *a++ = *ai++;
  201. X      k = i--; while (k--) *a++ = 0.0;
  202. X   }
  203. X
  204. X   a = store; int l = m1;
  205. X   for (k=0; k<n; k++)
  206. X   {
  207. X      Real x = *a; i = k; Real* aj = a;
  208. X      if (l < n) l++;
  209. X      for (j=k+1; j<l; j++)
  210. X         { aj += w; if (fabs(x) < fabs(*aj)) { x = *aj; i = j; } }
  211. X      indx[k] = i;
  212. X      if (x==0) { sing = TRUE; return; }
  213. X      if (i!=k)
  214. X      {
  215. X         d = !d; Real* ak = a; Real* ai = store + i * w; j = w;
  216. X         while (j--) { x = *ak; *ak++ = *ai; *ai++ = x; }
  217. X      }
  218. X      aj = a + w; Real* m = store2 + m1 * k;
  219. X      for (j=k+1; j<l; j++)
  220. X      {
  221. X         *m++ = x = *aj / *a; i = w; Real* ak = a;
  222. X     while (--i) { Real* aj1 = aj++; *aj1 = *aj - x * *(++ak); }
  223. X         *aj++ = 0.0;
  224. X      }
  225. X      a += w;
  226. X   }
  227. X}
  228. X
  229. Xvoid BandLUMatrix::lubksb(Real* B, int mini)
  230. X{
  231. X   REPORT
  232. X   Tracer tr("BandLUMatrix::lubksb");
  233. X   if (sing) Throw(SingularException(*this));
  234. X   int n = nrows; int l = m1; int w = m1 + 1 + m2;
  235. X
  236. X   for (int k=0; k<n; k++)
  237. X   {
  238. X      int i = indx[k];
  239. X      if (i!=k) { Real x=B[k]; B[k]=B[i]; B[i]=x; }
  240. X      if (l<n) l++;
  241. X      Real* m = store2 + k*m1; Real* b = B+k; Real* bi = b;
  242. X      for (i=k+1; i<l; i++)  *(++bi) -= *m++ * *b;
  243. X   }
  244. X
  245. X   l = -m1;
  246. X   for (int i = n-1; i>=mini; i--)
  247. X   {
  248. X      Real* b = B + i; Real* bk = b; Real x = *bk;
  249. X      Real* a = store + w*i; Real y = *a;
  250. X      int k = l+m1; while (k--) x -=  *(++a) * *(++bk);
  251. X      *b = x / y;
  252. X      if (l < m2) l++;
  253. X   }
  254. X}
  255. X
  256. Xvoid BandLUMatrix::Solver(MatrixRowCol& mcout, const MatrixRowCol& mcin)
  257. X{
  258. X   REPORT
  259. X   Real* el = mcin.store; int i = mcin.skip;
  260. X   while (i--) *el++ = 0.0;
  261. X   el += mcin.storage; i = nrows - mcin.skip - mcin.storage;
  262. X   while (i--) *el++ = 0.0;
  263. X   lubksb(mcin.store, mcout.skip);
  264. X}
  265. X
  266. X// Do we need check for entirely zero output?
  267. X
  268. X
  269. Xvoid UpperBandMatrix::Solver(MatrixRowCol& mcout,
  270. X   const MatrixRowCol& mcin)
  271. X{
  272. X   REPORT
  273. X   Real* elx = mcin.store+mcout.skip; int i = mcin.skip-mcout.skip;
  274. X   while (i-- > 0) *elx++ = 0.0;
  275. X   int nr = mcin.skip+mcin.storage; elx = mcin.store+nr; Real* el = elx;
  276. X   int j = mcout.skip+mcout.storage-nr; i = nr-mcout.skip;
  277. X   while (j-- > 0) *elx++ = 0.0;
  278. X
  279. X   Real* Ael = store + (upper+1)*(i-1)+1; j = 0;
  280. X   while (i-- > 0)
  281. X   {
  282. X      elx = el; Real sum = 0.0; int jx = j;
  283. X      while (jx--) sum += *(--Ael) * *(--elx);
  284. X      elx--; *elx = (*elx - sum) / *(--Ael);
  285. X      if (j<upper) Ael -= upper - (++j); else el--;
  286. X   }
  287. X}
  288. X
  289. Xvoid LowerBandMatrix::Solver(MatrixRowCol& mcout,
  290. X   const MatrixRowCol& mcin)
  291. X{
  292. X   REPORT
  293. X   Real* elx = mcin.store+mcout.skip; int i = mcin.skip-mcout.skip;
  294. X   while (i-- > 0) *elx++ = 0.0;
  295. X   int nc = mcin.skip; i = nc+mcin.storage; elx = mcin.store+i;
  296. X   int nr = mcout.skip+mcout.storage; int j = nr-i; i = nr-nc;
  297. X   while (j-- > 0) *elx++ = 0.0;
  298. X
  299. X   Real* el = mcin.store+nc; Real* Ael = store + (lower+1)*nc + lower; j = 0;
  300. X   while (i-- > 0)
  301. X   {
  302. X      elx = el; Real sum = 0.0; int jx = j;
  303. X      while (jx--) sum += *Ael++ * *elx++;
  304. X      *elx = (*elx - sum) / *Ael++;
  305. X      if (j<lower) Ael += lower - (++j); else el++;
  306. X   }
  307. X}
  308. X
  309. X
  310. XLogAndSign BandMatrix::LogDeterminant() const
  311. X{
  312. X   REPORT
  313. X   BandLUMatrix C(*this); return C.LogDeterminant();
  314. X}
  315. X
  316. XLogAndSign LowerBandMatrix::LogDeterminant() const
  317. X{
  318. X   REPORT
  319. X   int i = nrows; LogAndSign sum; Real* s = store + lower; int j = lower + 1;
  320. X   while (i--) { sum *= *s; s += j; }
  321. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  322. X}
  323. X
  324. XLogAndSign UpperBandMatrix::LogDeterminant() const
  325. X{
  326. X   REPORT
  327. X   int i = nrows; LogAndSign sum; Real* s = store; int j = upper + 1;
  328. X   while (i--) { sum *= *s; s += j; }
  329. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  330. X}
  331. X
  332. XGeneralMatrix* SymmetricBandMatrix::MakeSolver()
  333. X{
  334. X   REPORT
  335. X   GeneralMatrix* gm = new BandLUMatrix(*this);
  336. X   MatrixErrorNoSpace(gm); gm->ReleaseAndDelete(); return gm;
  337. X}
  338. X
  339. XSymmetricBandMatrix::SymmetricBandMatrix(const BaseMatrix& M)
  340. X{
  341. X   REPORT1  // CheckConversion(M);
  342. X   MatrixConversionCheck mcc;
  343. X   GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::SB);
  344. X   GetMatrix(gmx);
  345. X}
  346. X
  347. XGeneralMatrix* SymmetricBandMatrix::Transpose(TransposedMatrix*, MatrixType mt)
  348. X{ REPORT  return Evaluate(mt); }
  349. X
  350. XLogAndSign SymmetricBandMatrix::LogDeterminant() const
  351. X{
  352. X   REPORT
  353. X   BandLUMatrix C(*this); return C.LogDeterminant();
  354. X}
  355. X
  356. Xvoid SymmetricBandMatrix::SetParameters(const GeneralMatrix* gmx)
  357. X{ lower = gmx->BandWidth().lower; }
  358. X
  359. Xvoid SymmetricBandMatrix::ReDimension(int n, int lb)
  360. X{
  361. X   REPORT
  362. X   Tracer tr("SymmetricBandMatrix::ReDimension");
  363. X   if (lb<0) Throw(ProgramException("Undefined bandwidth"));
  364. X   lower = (lb<=n) ? lb : n-1;
  365. X   GeneralMatrix::ReDimension(n,n,n*(lower+1));
  366. X}
  367. X
  368. Xvoid SymmetricBandMatrix::operator=(const BaseMatrix& X)
  369. X{
  370. X   REPORT // CheckConversion(X);
  371. X   MatrixConversionCheck mcc;
  372. X   Eq(X,MatrixType::SB);
  373. X}
  374. X
  375. Xvoid SymmetricBandMatrix::CornerClear() const
  376. X{
  377. X   // set unused parts of BandMatrix to zero
  378. X   REPORT
  379. X   int i = lower; Real* s = store; int bw = lower + 1;
  380. X   while (i)
  381. X      { int j = i--; Real* sj = s; s += bw; while (j--) *sj++ = 0.0; }
  382. X}
  383. X
  384. XMatrixBandWidth SymmetricBandMatrix::BandWidth() const
  385. X   { return MatrixBandWidth(lower,lower); }
  386. X
  387. Xinline Real square(Real x) { return x*x; }
  388. X
  389. X
  390. XReal SymmetricBandMatrix::SumSquare() const
  391. X{
  392. X   REPORT
  393. X   CornerClear();
  394. X   Real sum1=0.0; Real sum2=0.0; Real* s=store; int i=nrows; int l=lower;
  395. X   while (i--)
  396. X      { int j = l; while (j--) sum2 += square(*s++); sum1 += square(*s++); }
  397. X   ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
  398. X}
  399. X
  400. XReal SymmetricBandMatrix::SumAbsoluteValue() const
  401. X{
  402. X   REPORT
  403. X   CornerClear();
  404. X   Real sum1=0.0; Real sum2=0.0; Real* s=store; int i=nrows; int l=lower;
  405. X   while (i--)
  406. X      { int j = l; while (j--) sum2 += fabs(*s++); sum1 += fabs(*s++); }
  407. X   ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
  408. X}
  409. X
  410. END_OF_FILE
  411. if test 10343 -ne `wc -c <'bandmat.cxx'`; then
  412.     echo shar: \"'bandmat.cxx'\" unpacked with wrong size!
  413. fi
  414. # end of 'bandmat.cxx'
  415. fi
  416. if test -f 'cholesky.cxx' -a "${1}" != "-c" ; then 
  417.   echo shar: Will not clobber existing file \"'cholesky.cxx'\"
  418. else
  419. echo shar: Extracting \"'cholesky.cxx'\" \(1783 characters\)
  420. sed "s/^X//" >'cholesky.cxx' <<'END_OF_FILE'
  421. X//$$ cholesky.cxx                     cholesky decomposition
  422. X
  423. X// Copyright (C) 1991,2,3: R B Davies
  424. X
  425. X#define WANT_MATH
  426. X
  427. X#include "include.h"
  428. X
  429. X#include "newmat.h"
  430. X
  431. X
  432. X/********* Cholesky decomposition of a positive definite matrix *************/
  433. X
  434. X// Suppose S is symmetrix and positive definite. Then there exists a unique
  435. X// lower triangular matrix L such that L L.t() = S;
  436. X
  437. Xstatic Real square(Real x) { return x*x; }
  438. X
  439. XReturnMatrix Cholesky(const SymmetricMatrix& S)
  440. X{
  441. X   Tracer trace("Cholesky");
  442. X   int nr = S.Nrows();
  443. X   LowerTriangularMatrix T(nr);
  444. X   Real* s = S.Store(); Real* t = T.Store(); Real* ti = t;
  445. X   for (int i=0; i<nr; i++)
  446. X   {
  447. X      Real* tj = t; Real sum; int k;
  448. X      for (int j=0; j<i; j++)
  449. X      {
  450. X     Real* tk = ti; sum = 0.0; k = j;
  451. X     while (k--) { sum += *tj++ * *tk++; }
  452. X     *tk = (*s++ - sum) / *tj++;
  453. X      }
  454. X      sum = 0.0; k = i;
  455. X      while (k--) { sum += square(*ti++); }
  456. X      Real d = *s++ - sum;
  457. X      if (d<=0.0) Throw(NPDException(S));
  458. X      *ti++ = sqrt(d);
  459. X   }
  460. X   T.Release(); return (ReturnMatrix)T;
  461. X}
  462. X
  463. XReturnMatrix Cholesky(const SymmetricBandMatrix& S)
  464. X{
  465. X   Tracer trace("Band-Cholesky");
  466. X   int nr = S.Nrows(); int m = S.lower;
  467. X   LowerBandMatrix T(nr,m);
  468. X   Real* s = S.Store(); Real* t = T.Store(); Real* ti = t;
  469. X
  470. X   for (int i=0; i<nr; i++)
  471. X   {
  472. X      Real* tj = t; Real sum; int l;
  473. X      if (i<m) { l = m-i; s += l; ti += l; l = i; }
  474. X      else { t += (m+1); l = m; }
  475. X
  476. X      for (int j=0; j<l; j++)
  477. X      {
  478. X     Real* tk = ti; sum = 0.0; int k = j; tj += (m-j);
  479. X     while (k--) { sum += *tj++ * *tk++; }
  480. X     *tk = (*s++ - sum) / *tj++;
  481. X      }
  482. X      sum = 0.0;
  483. X      while (l--) { sum += square(*ti++); }
  484. X      Real d = *s++ - sum;
  485. X      if (d<=0.0)  Throw(NPDException(S));
  486. X      *ti++ = sqrt(d);
  487. X   }
  488. X
  489. X   T.Release(); return (ReturnMatrix)T;
  490. X}
  491. X
  492. END_OF_FILE
  493. if test 1783 -ne `wc -c <'cholesky.cxx'`; then
  494.     echo shar: \"'cholesky.cxx'\" unpacked with wrong size!
  495. fi
  496. # end of 'cholesky.cxx'
  497. fi
  498. if test -f 'evalue.cxx' -a "${1}" != "-c" ; then 
  499.   echo shar: Will not clobber existing file \"'evalue.cxx'\"
  500. else
  501. echo shar: Extracting \"'evalue.cxx'\" \(7813 characters\)
  502. sed "s/^X//" >'evalue.cxx' <<'END_OF_FILE'
  503. X//$$evalue.cxx                           eigen-value decomposition
  504. X
  505. X// Copyright (C) 1991,2,3: R B Davies
  506. X
  507. X#define WANT_MATH
  508. X
  509. X#include "include.h"
  510. X#include "newmat.h"
  511. X#include "newmatrm.h"
  512. X#include "precisio.h"
  513. X
  514. X
  515. Xstatic void tred2(const SymmetricMatrix& A, DiagonalMatrix& D,
  516. X   DiagonalMatrix& E, Matrix& Z)
  517. X{
  518. X   Tracer et("Evalue(tred2)");
  519. X   Real tol =
  520. X      FloatingPointPrecision::Minimum()/FloatingPointPrecision::Epsilon();
  521. X   int n = A.Nrows(); Z.ReDimension(n,n); Z.Inject(A);
  522. X   D.ReDimension(n); E.ReDimension(n);
  523. X   Real* z = Z.Store();
  524. X
  525. X   for (int i=n-1; i > 0; i--)                   // i=0 is excluded
  526. X   {
  527. X      Real f = Z.element(i,i-1); Real g = 0.0;
  528. X      int k = i-1; Real* zik = z + i*n;
  529. X      while (k--) g += square(*zik++);
  530. X      Real h = g + square(f);
  531. X      if (g <= tol) { E.element(i) = f; h = 0.0; }
  532. X      else
  533. X      {
  534. X     g = sign(-sqrt(h), f); E.element(i) = g; h -= f*g;
  535. X     Z.element(i,i-1) = f-g; f = 0.0;
  536. X         Real* zji = z + i; Real* zij = z + i*n; Real* ej = E.Store();
  537. X     for (int j=0; j<i; j++)
  538. X     {
  539. X        *zji = (*zij++)/h; g = 0.0;
  540. X            Real* zjk = z + j*n; zik = z + i*n;
  541. X            k = j; while (k--) g += *zjk++ * (*zik++);
  542. X            k = i-j; while (k--) { g += *zjk * (*zik++); zjk += n; }
  543. X        *ej++ = g/h; f += g * (*zji); zji += n;
  544. X     }
  545. X     Real hh = f / (h + h); zij = z + i*n; ej = E.Store();
  546. X     for (j=0; j<i; j++)
  547. X     {
  548. X        f = *zij++; g = *ej - hh * f; *ej++ = g;
  549. X            Real* zjk = z + j*n; Real* zik = z + i*n;
  550. X            Real* ek = E.Store(); k = j+1;
  551. X            while (k--)  *zjk++ -= ( f*(*ek++) + g*(*zik++) ); 
  552. X     }
  553. X      }
  554. X      D.element(i) = h;
  555. X   }
  556. X
  557. X   D.element(0) = 0.0; E.element(0) = 0.0;
  558. X   for (i=0; i<n; i++)
  559. X   {
  560. X      if (D.element(i) != 0.0)
  561. X      {
  562. X     for (int j=0; j<i; j++)
  563. X     {
  564. X        Real g = 0.0;
  565. X            Real* zik = z + i*n; Real* zkj = z + j;
  566. X            int k = i; while (k--) { g += *zik++ * (*zkj); zkj += n; }
  567. X            Real* zki = z + i; zkj = z + j;
  568. X            k = i; while (k--) { *zkj -= g * (*zki); zkj += n; zki += n; }
  569. X     }
  570. X      }
  571. X      Real* zij = z + i*n; Real* zji = z + i;
  572. X      int j = i; while (j--)  { *zij++ = 0.0; *zji = 0.0; zji += n; }
  573. X      D.element(i) = *zij; *zij = 1.0;
  574. X   }
  575. X}
  576. X
  577. Xstatic void tql2(DiagonalMatrix& D, DiagonalMatrix& E, Matrix& Z)
  578. X{
  579. X   Tracer et("Evalue(tql2)");
  580. X   Real eps = FloatingPointPrecision::Epsilon();
  581. X   int n = D.Nrows(); Real* z = Z.Store();
  582. X   for (int l=1; l<n; l++) E.element(l-1) = E.element(l);
  583. X   Real b = 0.0; Real f = 0.0; E.element(n-1) = 0.0;
  584. X   for (l=0; l<n; l++)
  585. X   {
  586. X      int i,j;
  587. X      Real& dl = D.element(l); Real& el = E.element(l);
  588. X      Real h = eps * ( fabs(dl) + fabs(el) );
  589. X      if (b < h) b = h;
  590. X      for (int m=l; m<n; m++) if (fabs(E.element(m)) <= b) break;
  591. X      Boolean test = FALSE;
  592. X      for (j=0; j<30; j++)
  593. X      {
  594. X     if (m==l) { test = TRUE; break; }
  595. X     Real& dl1 = D.element(l+1);
  596. X     Real g = dl; Real p = (dl1-g) / (2.0*el); Real r = sqrt(p*p + 1.0);
  597. X     dl = el / (p < 0.0 ? p-r : p+r); Real h = g - dl; f += h;
  598. X     Real* dlx = &dl1; i = n-l-1; while (i--) *dlx++ -= h;
  599. X
  600. X     p = D.element(m); Real c = 1.0; Real s = 0.0;
  601. X     for (i=m-1; i>=l; i--)
  602. X     {
  603. X        Real ei = E.element(i); Real di = D.element(i);
  604. X        Real& ei1 = E.element(i+1);
  605. X        g = c * ei; h = c * p;
  606. X        if ( fabs(p) >= fabs(ei))
  607. X        {
  608. X           c = ei / p; r = sqrt(c*c + 1.0);
  609. X           ei1 = s*p*r; s = c/r; c = 1.0/r;
  610. X        }
  611. X        else
  612. X        {
  613. X           c = p / ei; r = sqrt(c*c + 1.0);
  614. X           ei1 = s * ei * r; s = 1.0/r; c /= r;
  615. X        }
  616. X        p = c * di - s*g; D.element(i+1) = h + s * (c*g + s*di);
  617. X
  618. X        Real* zki = z + i; Real* zki1 = zki + 1; int k = n;
  619. X        while (k--)
  620. X        {
  621. X           h = *zki1; *zki1 = s*(*zki) + c*h; *zki = c*(*zki) - s*h;
  622. X           zki += n; zki1 += n;
  623. X        }
  624. X     }
  625. X     el = s*p; dl = c*p;
  626. X     if (fabs(el) <= b) { test = TRUE; break; }
  627. X      }
  628. X      if (!test) Throw ( ConvergenceException(D) );
  629. X      dl += f;
  630. X   }
  631. X
  632. X   for (int i=0; i<n; i++)
  633. X   {
  634. X      int k = i; Real p = D.element(i);
  635. X      for (int j=i+1; j<n; j++)
  636. X         { if (D.element(j) < p) { k = j; p = D.element(j); } }
  637. X      if (k != i)
  638. X      {
  639. X         D.element(k) = D.element(i); D.element(i) = p; int j = n;
  640. X     Real* zji = z + i; Real* zjk = z + k;
  641. X         while (j--) { p = *zji; *zji = *zjk; *zjk = p; zji += n; zjk += n; }
  642. X      }
  643. X   }
  644. X
  645. X}
  646. X
  647. Xstatic void tred3(const SymmetricMatrix& X, DiagonalMatrix& D,
  648. X   DiagonalMatrix& E, SymmetricMatrix& A)
  649. X{
  650. X   Tracer et("Evalue(tred3)");
  651. X   Real tol =
  652. X      FloatingPointPrecision::Minimum()/FloatingPointPrecision::Epsilon();
  653. X   int n = X.Nrows(); A = X; D.ReDimension(n); E.ReDimension(n);
  654. X   Real* ei = E.Store() + n;
  655. X   for (int i = n-1; i >= 0; i--)
  656. X   {
  657. X      Real h = 0.0; Real f;
  658. X      Real* d = D.Store(); Real* a = A.Store() + (i*(i+1))/2; int k = i;
  659. X      while (k--) { f = *a++; *d++ = f; h += square(f); }
  660. X      if (h <= tol) { *(--ei) = 0.0; h = 0.0; }
  661. X      else
  662. X      {
  663. X     Real g = sign(-sqrt(h), f); *(--ei) = g; h -= f*g;
  664. X         f -= g; *(d-1) = f; *(a-1) = f; f = 0.0;
  665. X         Real* dj = D.Store(); Real* ej = E.Store();
  666. X         for (int j = 0; j < i; j++)
  667. X         {
  668. X            Real* dk = D.Store(); Real* ak = A.Store()+(j*(j+1))/2;
  669. X            Real g = 0.0; k = j;
  670. X            while (k--)  g += *ak++ * *dk++;
  671. X            k = i-j; int l = j; 
  672. X            while (k--) { g += *ak * *dk++; ak += ++l; }
  673. X        g /= h; *ej++ = g; f += g * *dj++;
  674. X         }  
  675. X     Real hh = f / (2 * h); Real* ak = A.Store();
  676. X         dj = D.Store(); ej = E.Store();
  677. X         for (j = 0; j < i; j++)
  678. X         {
  679. X        f = *dj++; g = *ej - hh * f; *ej++ = g;
  680. X            Real* dk = D.Store(); Real* ek = E.Store(); k = j+1;
  681. X        while (k--) { *ak++ -= (f * *ek++ + g * *dk++); }
  682. X     }
  683. X      }
  684. X      *d = *a; *a = h;
  685. X   }
  686. X}
  687. X
  688. Xstatic void tql1(DiagonalMatrix& D, DiagonalMatrix& E)
  689. X{
  690. X   Tracer et("Evalue(tql1)");
  691. X   Real eps = FloatingPointPrecision::Epsilon();
  692. X   int n = D.Nrows();
  693. X   for (int l=1; l<n; l++) E.element(l-1) = E.element(l);
  694. X   Real b = 0.0; Real f = 0.0; E.element(n-1) = 0.0;
  695. X   for (l=0; l<n; l++)
  696. X   {
  697. X      int i,j;
  698. X      Real& dl = D.element(l); Real& el = E.element(l);
  699. X      Real h = eps * ( fabs(dl) + fabs(el) );
  700. X      if (b < h) b = h;
  701. X      for (int m=l; m<n; m++) if (fabs(E.element(m)) <= b) break;
  702. X      Boolean test = FALSE;
  703. X      for (j=0; j<30; j++)
  704. X      {
  705. X         if (m==l) { test = TRUE; break; }
  706. X         Real& dl1 = D.element(l+1);
  707. X     Real g = dl; Real p = (dl1-g) / (2.0*el); Real r = sqrt(p*p + 1.0);
  708. X     dl = el / (p < 0.0 ? p-r : p+r); Real h = g - dl; f += h;
  709. X         Real* dlx = &dl1; i = n-l-1; while (i--) *dlx++ -= h;
  710. X
  711. X     p = D.element(m); Real c = 1.0; Real s = 0.0;
  712. X     for (i=m-1; i>=l; i--)
  713. X     {
  714. X            Real ei = E.element(i); Real di = D.element(i);
  715. X            Real& ei1 = E.element(i+1);
  716. X        g = c * ei; h = c * p;
  717. X        if ( fabs(p) >= fabs(ei))
  718. X        {
  719. X           c = ei / p; r = sqrt(c*c + 1.0); 
  720. X               ei1 = s*p*r; s = c/r; c = 1.0/r;
  721. X        }
  722. X        else
  723. X        {
  724. X           c = p / ei; r = sqrt(c*c + 1.0);
  725. X           ei1 = s * ei * r; s = 1.0/r; c /= r;
  726. X        }
  727. X        p = c * di - s*g; D.element(i+1) = h + s * (c*g + s*di);
  728. X     }
  729. X     el = s*p; dl = c*p;
  730. X     if (fabs(el) <= b) { test = TRUE; break; }
  731. X      }
  732. X      if (!test) Throw ( ConvergenceException(D) );
  733. X      Real p = dl + f;
  734. X      test = FALSE;
  735. X      for (i=l; i>0; i--)
  736. X      {
  737. X         if (p < D.element(i-1)) D.element(i) = D.element(i-1);
  738. X         else { test = TRUE; break; }
  739. X      }
  740. X      if (!test) i=0;
  741. X      D.element(i) = p;
  742. X   }
  743. X}
  744. X
  745. Xvoid EigenValues(const SymmetricMatrix& A, DiagonalMatrix& D, Matrix& Z)
  746. X{ DiagonalMatrix E; tred2(A, D, E, Z); tql2(D, E, Z); }
  747. X
  748. Xvoid EigenValues(const SymmetricMatrix& X, DiagonalMatrix& D)
  749. X{ DiagonalMatrix E; SymmetricMatrix A; tred3(X,D,E,A); tql1(D,E); }
  750. X
  751. Xvoid EigenValues(const SymmetricMatrix& X, DiagonalMatrix& D,
  752. X   SymmetricMatrix& A)
  753. X{ DiagonalMatrix E; tred3(X,D,E,A); tql1(D,E); }
  754. X
  755. END_OF_FILE
  756. if test 7813 -ne `wc -c <'evalue.cxx'`; then
  757.     echo shar: \"'evalue.cxx'\" unpacked with wrong size!
  758. fi
  759. # end of 'evalue.cxx'
  760. fi
  761. if test -f 'example.txt' -a "${1}" != "-c" ; then 
  762.   echo shar: Will not clobber existing file \"'example.txt'\"
  763. else
  764. echo shar: Extracting \"'example.txt'\" \(1834 characters\)
  765. sed "s/^X//" >'example.txt' <<'END_OF_FILE'
  766. X
  767. XDemonstration of Matrix package
  768. X
  769. X
  770. X
  771. XTest 1 - traditional
  772. X
  773. XEstimates and their standard errors
  774. X
  775. X1.391655    0.531878
  776. X1.983103    0.209317
  777. X0.952208    0.277307
  778. X
  779. XObservations, fitted value, residual value, hat value
  780. X2.4    1.7    8.3    7.769    0.53    0.28
  781. X1.8    0.9    5.5    5.818    -0.318    0.189
  782. X2.4    1.6    8    7.674    0.325    0.228
  783. X3    1.9    8.5    9.15    -0.65    0.445
  784. X2    0.5    5.7    5.833    -0.133    0.271
  785. X1.2    0.6    4.4    4.342    0.057    0.479
  786. X2    1.1    6.3    6.405    -0.105    0.143
  787. X2.7    1    7.9    7.698    0.201    0.153
  788. X3.6    0.5    9.1    9.006    0.093    0.807
  789. X
  790. X
  791. X
  792. X
  793. XTest 2 - Cholesky
  794. X
  795. XEstimates and their standard errors
  796. X
  797. X1.391655    0.531878
  798. X1.983103    0.209317
  799. X0.952208    0.277307
  800. X
  801. XObservations, fitted value, residual value, hat value
  802. X2.4    1.7    8.3    7.769    0.53    0.28
  803. X1.8    0.9    5.5    5.818    -0.318    0.189
  804. X2.4    1.6    8    7.674    0.325    0.228
  805. X3    1.9    8.5    9.15    -0.65    0.445
  806. X2    0.5    5.7    5.833    -0.133    0.271
  807. X1.2    0.6    4.4    4.342    0.057    0.479
  808. X2    1.1    6.3    6.405    -0.105    0.143
  809. X2.7    1    7.9    7.698    0.201    0.153
  810. X3.6    0.5    9.1    9.006    0.093    0.807
  811. X
  812. X
  813. X
  814. X
  815. XTest 3 - Householder triangularisation
  816. X
  817. XEstimates and their standard errors
  818. X
  819. X1.391655    0.531878
  820. X1.983103    0.209317
  821. X0.952208    0.277307
  822. X
  823. XObservations, fitted value, residual value, hat value
  824. X2.4    1.7    8.3    7.769    0.53    0.28
  825. X1.8    0.9    5.5    5.818    -0.318    0.189
  826. X2.4    1.6    8    7.674    0.325    0.228
  827. X3    1.9    8.5    9.15    -0.65    0.445
  828. X2    0.5    5.7    5.833    -0.133    0.271
  829. X1.2    0.6    4.4    4.342    0.057    0.479
  830. X2    1.1    6.3    6.405    -0.105    0.143
  831. X2.7    1    7.9    7.698    0.201    0.153
  832. X3.6    0.5    9.1    9.006    0.093    0.807
  833. X
  834. X
  835. X
  836. X
  837. XTest 4 - singular value
  838. X
  839. XEstimates and their standard errors
  840. X
  841. X1.391655    0.531878
  842. X1.983103    0.209317
  843. X0.952208    0.277307
  844. X
  845. XObservations, fitted value, residual value, hat value
  846. X2.4    1.7    8.3    7.769    0.53    0.28
  847. X1.8    0.9    5.5    5.818    -0.318    0.189
  848. X2.4    1.6    8    7.674    0.325    0.228
  849. X3    1.9    8.5    9.15    -0.65    0.445
  850. X2    0.5    5.7    5.833    -0.133    0.271
  851. X1.2    0.6    4.4    4.342    0.057    0.479
  852. X2    1.1    6.3    6.405    -0.105    0.143
  853. X2.7    1    7.9    7.698    0.201    0.153
  854. X3.6    0.5    9.1    9.006    0.093    0.807
  855. X
  856. X
  857. X
  858. X
  859. XChecking for lost memory: 587792388 587792388  - ok
  860. END_OF_FILE
  861. if test 1834 -ne `wc -c <'example.txt'`; then
  862.     echo shar: \"'example.txt'\" unpacked with wrong size!
  863. fi
  864. # end of 'example.txt'
  865. fi
  866. if test -f 'except.cxx' -a "${1}" != "-c" ; then 
  867.   echo shar: Will not clobber existing file \"'except.cxx'\"
  868. else
  869. echo shar: Extracting \"'except.cxx'\" \(7617 characters\)
  870. sed "s/^X//" >'except.cxx' <<'END_OF_FILE'
  871. X//$$except.cxx                        Exception handler
  872. X
  873. X
  874. X
  875. X#define WANT_STREAM                  // include.h will get stream fns
  876. X
  877. X
  878. X#include "include.h"                 // include standard files
  879. X#include "boolean.h"
  880. X
  881. X
  882. X#include "except.h"                  // for exception handling
  883. X
  884. X//#define REG_DEREG                    // for print out uses of new/delete
  885. X//#define CLEAN_LIST                   // to print entries being added to
  886. X                                       // or deleted from cleanup list
  887. X
  888. X
  889. Xvoid Throw()
  890. X{
  891. X   for (Janitor* jan = JumpBase::jl->janitor; jan; jan = jan->NextJanitor)
  892. X      jan->CleanUp();
  893. X   JumpBase::jl = JumpBase::jl->ji;
  894. X   if ( ! JumpBase::jl ) Terminate();
  895. X   Exception::last = JumpBase::jl->trace;
  896. X   longjmp(JumpBase::jl->env, 1);
  897. X}
  898. X
  899. Xvoid Throw(const Exception& exc) { JumpBase::type = exc.type(); Throw(); }
  900. X
  901. X
  902. Xvoid Exception::PrintTrace(Boolean)
  903. X{
  904. X   cout << "\n";
  905. X   {
  906. X      for (Tracer* et = last; et; et=et->previous)
  907. X     cout << "  * " << et->entry << "\n";
  908. X   }
  909. X}
  910. X
  911. XException::Exception(int action)
  912. X{
  913. X   if (action)
  914. X   {
  915. X      cout << "\nAn exception has occurred: call trace follows.";
  916. X      PrintTrace();
  917. X      if (action < 0) exit(1);
  918. X   }
  919. X}
  920. X
  921. XJanitor::Janitor()
  922. X{
  923. X   if (do_not_link)
  924. X   {
  925. X      do_not_link = FALSE; NextJanitor = 0; OnStack = FALSE;
  926. X#ifdef CLEAN_LIST
  927. X      cout << "Not added to clean-list " << (unsigned long)this << "\n";
  928. X#endif
  929. X   }
  930. X   else
  931. X   {
  932. X      OnStack = TRUE;
  933. X#ifdef CLEAN_LIST
  934. X      cout << "Add to       clean-list " << (unsigned long)this << "\n";
  935. X#endif
  936. X      NextJanitor = JumpBase::jl->janitor; JumpBase::jl->janitor=this;
  937. X   }
  938. X}
  939. X
  940. XJanitor::~Janitor()
  941. X{
  942. X   // expect the item to be deleted to be first on list
  943. X   // but must be prepared to search list
  944. X   if (OnStack)
  945. X   {
  946. X#ifdef CLEAN_LIST
  947. X      cout << "Delete from  clean-list " << (unsigned long)this << "\n";
  948. X#endif
  949. X      Janitor* lastjan = JumpBase::jl->janitor;
  950. X      if (this == lastjan) JumpBase::jl->janitor = NextJanitor;
  951. X      else
  952. X      {
  953. X     for (Janitor* jan = lastjan->NextJanitor; jan;
  954. X        jan = lastjan->NextJanitor)
  955. X     {
  956. X        if (jan==this)
  957. X           { lastjan->NextJanitor = jan->NextJanitor; return; }
  958. X        lastjan=jan;
  959. X     }
  960. X
  961. X         cout << "\nCannot resolve memory linked list\n";
  962. X         cout << "See notes in except.cxx for details\n";
  963. X     Throw(Exception(-1));
  964. X/*
  965. XThis message occurs when a call to ~Janitor() occurs, apparently without a
  966. Xcorresponding call to Janitor(). This could happen if my way of deciding
  967. Xwhether a constructor is being called by new fails. Possibly also if
  968. Xdelete is applied an object on the stack (ie not called by new). Otherwise,
  969. Xit is a bug in Newmat or your compiler. If you don't #define
  970. XTEMPS_DESTROYED_QUICKLY you will get this error with Microsoft C 7.0. There
  971. Xare probably situations where you will get this when you do define
  972. XTEMPS_DESTROYED_QUICKLY. This is a bug in MSC. Beware of "operator" statements
  973. Xfor defining conversions; particularly for converting from a Base class to
  974. Xa Derived class. 
  975. X
  976. XYou may get away with simply deleting this error message and Throw statement
  977. Xif you can't find a better way of overcoming the problem. In any case please
  978. Xtell me if you get this error message, particularly for compilers apart from
  979. XMicrosoft C.
  980. X*/
  981. X      }
  982. X   }
  983. X}
  984. X
  985. XJumpItem* JumpBase::jl = 0;
  986. Xlong JumpBase::type;
  987. XTracer* Exception::last = 0;
  988. X
  989. XBoolean Janitor::do_not_link = FALSE;
  990. X
  991. Xstatic JumpItem JI;                  // need JumpItem at head of list
  992. X
  993. X
  994. X
  995. Xvoid Terminate()
  996. X{
  997. X   cout << "\nThere has been an exception with no handler - exiting\n";
  998. X   exit(1);
  999. X}
  1000. X
  1001. X
  1002. X
  1003. X
  1004. X
  1005. X
  1006. X#ifdef DO_FREE_CHECK
  1007. X// Routines for tracing whether new and delete calls are balanced
  1008. X
  1009. XFreeCheckLink::FreeCheckLink() : next(FreeCheck::next)
  1010. X   { FreeCheck::next = this; }
  1011. X
  1012. XFCLClass::FCLClass(void* t, char* name) : ClassName(name) { ClassStore=t; }
  1013. X   
  1014. XFCLRealArray::FCLRealArray(void* t, char* o, int s)
  1015. X  : Operation(o), size(s) { ClassStore=t; }
  1016. X
  1017. XFCLIntArray::FCLIntArray(void* t, char* o, int s)
  1018. X  : Operation(o), size(s) { ClassStore=t; }
  1019. X
  1020. XFreeCheckLink* FreeCheck::next = 0;
  1021. X
  1022. Xvoid FCLClass::Report()
  1023. X{ cout << "   " << ClassName << "   " << (unsigned long)ClassStore << "\n"; }
  1024. X
  1025. Xvoid FCLRealArray::Report()
  1026. X{
  1027. X   cout << "   " << Operation << "   " << (unsigned long)ClassStore << 
  1028. X      "   " << size << "\n";
  1029. X}
  1030. X
  1031. Xvoid FCLIntArray::Report()
  1032. X{
  1033. X   cout << "   " << Operation << "   " << (unsigned long)ClassStore << 
  1034. X      "   " << size << "\n";
  1035. X}
  1036. X
  1037. Xvoid FreeCheck::Register(void* t, char* name)
  1038. X{
  1039. X   FCLClass* f = new FCLClass(t,name);
  1040. X   if (!f) { cout << "Out of memory in FreeCheck\n"; exit(1); }
  1041. X#ifdef REG_DEREG
  1042. X   cout << "Registering   " << name << "   " << (unsigned long)t << "\n";
  1043. X#endif
  1044. X}
  1045. X
  1046. Xvoid FreeCheck::RegisterR(void* t, char* o, int s)
  1047. X{
  1048. X   FCLRealArray* f = new FCLRealArray(t,o,s);
  1049. X   if (!f) { cout << "Out of memory in FreeCheck\n"; exit(1); }
  1050. X#ifdef REG_DEREG
  1051. X   cout << o << "   " << s << "   " << (unsigned long)t << "\n";
  1052. X#endif
  1053. X}
  1054. X
  1055. Xvoid FreeCheck::RegisterI(void* t, char* o, int s)
  1056. X{
  1057. X   FCLIntArray* f = new FCLIntArray(t,o,s);
  1058. X   if (!f) { cout << "Out of memory in FreeCheck\n"; exit(1); }
  1059. X#ifdef REG_DEREG
  1060. X   cout << o << "   " << s << "   " << (unsigned long)t << "\n";
  1061. X#endif
  1062. X}
  1063. X
  1064. Xvoid FreeCheck::DeRegister(void* t, char* name)
  1065. X{
  1066. X   FreeCheckLink* last = 0;
  1067. X#ifdef REG_DEREG
  1068. X   cout << "Deregistering " << name << "   " << (unsigned long)t << "\n";
  1069. X#endif
  1070. X   for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
  1071. X   {
  1072. X      if (fcl->ClassStore==t)
  1073. X      {
  1074. X     if (last) last->next = fcl->next; else next = fcl->next;
  1075. X     delete fcl; return;
  1076. X      }
  1077. X      last = fcl;
  1078. X   }
  1079. X   cout << "\nRequest to delete non-existent object of class and location:\n";
  1080. X   cout << "   " << name << "   " << (unsigned long)t << "\n";
  1081. X   Exception::PrintTrace(TRUE);
  1082. X   cout << "\n";
  1083. X}
  1084. X
  1085. Xvoid FreeCheck::DeRegisterR(void* t, char* o, int s)
  1086. X{
  1087. X   FreeCheckLink* last = 0;
  1088. X#ifdef REG_DEREG
  1089. X   cout << o << "   " << s << "   " << (unsigned long)t << "\n";
  1090. X#endif
  1091. X   for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
  1092. X   {
  1093. X      if (fcl->ClassStore==t)
  1094. X      {
  1095. X     if (last) last->next = fcl->next; else next = fcl->next;
  1096. X     if (((FCLRealArray*)fcl)->size != s)
  1097. X     {
  1098. X        cout << "\nArray sizes don't agree:\n";
  1099. X        cout << "   " << o << "   " << (unsigned long)t
  1100. X           << "   " << s << "\n";
  1101. X        Exception::PrintTrace(TRUE);
  1102. X        cout << "\n";
  1103. X     }
  1104. X     delete fcl; return;
  1105. X      }
  1106. X      last = fcl;
  1107. X   }
  1108. X   cout << "\nRequest to delete non-existent real array:\n";
  1109. X   cout << "   " << o << "   " << (unsigned long)t << "   " << s << "\n";
  1110. X   Exception::PrintTrace(TRUE);
  1111. X   cout << "\n";
  1112. X}
  1113. X
  1114. Xvoid FreeCheck::DeRegisterI(void* t, char* o, int s)
  1115. X{
  1116. X   FreeCheckLink* last = 0;
  1117. X#ifdef REG_DEREG
  1118. X   cout << o << "   " << s << "   " << (unsigned long)t << "\n";
  1119. X#endif
  1120. X   for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
  1121. X   {
  1122. X      if (fcl->ClassStore==t)
  1123. X      {
  1124. X     if (last) last->next = fcl->next; else next = fcl->next;
  1125. X     if (((FCLIntArray*)fcl)->size != s)
  1126. X     {
  1127. X        cout << "\nArray sizes don't agree:\n";
  1128. X        cout << "   " << o << "   " << (unsigned long)t
  1129. X           << "   " << s << "\n";
  1130. X        Exception::PrintTrace(TRUE);
  1131. X        cout << "\n";
  1132. X     }
  1133. X     delete fcl; return;
  1134. X      }
  1135. X      last = fcl;
  1136. X   }
  1137. X   cout << "\nRequest to delete non-existent int array:\n";
  1138. X   cout << "   " << o << "   " << (unsigned long)t << "   " << s << "\n";
  1139. X   Exception::PrintTrace(TRUE);
  1140. X   cout << "\n";
  1141. X}
  1142. X
  1143. Xvoid FreeCheck::Status()
  1144. X{
  1145. X   if (next)
  1146. X   {
  1147. X      cout << "\nObjects of the following classes remain undeleted:\n";
  1148. X      for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next) fcl->Report();
  1149. X      cout << "\n";
  1150. X   }
  1151. X   else cout << "\nNo objects remain undeleted\n";
  1152. X}
  1153. X
  1154. X#endif
  1155. X
  1156. X
  1157. END_OF_FILE
  1158. if test 7617 -ne `wc -c <'except.cxx'`; then
  1159.     echo shar: \"'except.cxx'\" unpacked with wrong size!
  1160. fi
  1161. # end of 'except.cxx'
  1162. fi
  1163. if test -f 'fft.cxx' -a "${1}" != "-c" ; then 
  1164.   echo shar: Will not clobber existing file \"'fft.cxx'\"
  1165. else
  1166. echo shar: Extracting \"'fft.cxx'\" \(7012 characters\)
  1167. sed "s/^X//" >'fft.cxx' <<'END_OF_FILE'
  1168. X//$$ fft.cxx                         Fast fourier transform
  1169. X
  1170. X// Copyright (C) 1991,2,3: R B Davies
  1171. X
  1172. X
  1173. X#define WANT_MATH
  1174. X
  1175. X#include "include.h"
  1176. X
  1177. X#include "newmatap.h"
  1178. X
  1179. X
  1180. Xstatic void cossin(int n, int d, Real& c, Real& s)
  1181. X// calculate cos(twopi*n/d) and sin(twopi*n/d)
  1182. X// minimise roundoff error
  1183. X{
  1184. X   long n4 = n * 4; int sector = (int)floor( (Real)n4 / (Real)d + 0.5 );
  1185. X   n4 -= sector * d;
  1186. X   if (sector < 0) sector = 3 - (3 - sector) % 4; else sector %= 4;
  1187. X   Real ratio = 1.5707963267948966192 * (Real)n4 / (Real)d;
  1188. X
  1189. X   switch (sector)
  1190. X   {
  1191. X   case 0: c =  cos(ratio); s =  sin(ratio); break;
  1192. X   case 1: c = -sin(ratio); s =  cos(ratio); break;
  1193. X   case 2: c = -cos(ratio); s = -sin(ratio); break;
  1194. X   case 3: c =  sin(ratio); s = -cos(ratio); break;
  1195. X   }
  1196. X}
  1197. X
  1198. Xstatic void fftstep(ColumnVector& A, ColumnVector& B, ColumnVector& X,
  1199. X   ColumnVector& Y, int after, int now, int before)
  1200. X{
  1201. X   Tracer trace("FFT(step)");
  1202. X   // const Real twopi = 6.2831853071795864769;
  1203. X   const int gamma = after * before;  const int delta = now * after;
  1204. X   // const Real angle = twopi / delta;  Real temp;
  1205. X   // Real r_omega = cos(angle);  Real i_omega = -sin(angle);
  1206. X   Real r_arg = 1.0;  Real i_arg = 0.0;
  1207. X   Real* x = X.Store();  Real* y = Y.Store();   // pointers to array storage
  1208. X   const int m = A.Nrows() - gamma;
  1209. X
  1210. X   for (int j = 0; j < now; j++)
  1211. X   {
  1212. X      Real* a = A.Store(); Real* b = B.Store(); // pointers to array storage
  1213. X      Real* x1 = x; Real* y1 = y; x += after; y += after;
  1214. X      for (int ia = 0; ia < after; ia++)
  1215. X      {
  1216. X     // generate sins & cosines explicitly rather than iteratively
  1217. X     // for more accuracy; but slower
  1218. X     cossin(-(j*after+ia), delta, r_arg, i_arg);
  1219. X
  1220. X     Real* a1 = a++; Real* b1 = b++; Real* x2 = x1++; Real* y2 = y1++;
  1221. X     if (now==2)
  1222. X     {
  1223. X        int ib = before; while (ib--)
  1224. X        {
  1225. X           Real* a2 = m + a1; Real* b2 = m + b1; a1 += after; b1 += after;
  1226. X           Real r_value = *a2; Real i_value = *b2;
  1227. X           *x2 = r_value * r_arg - i_value * i_arg + *(a2-gamma);
  1228. X           *y2 = r_value * i_arg + i_value * r_arg + *(b2-gamma);
  1229. X           x2 += delta; y2 += delta;
  1230. X        }
  1231. X     }
  1232. X     else
  1233. X     {
  1234. X        int ib = before; while (ib--)
  1235. X        {
  1236. X           Real* a2 = m + a1; Real* b2 = m + b1; a1 += after; b1 += after;
  1237. X           Real r_value = *a2; Real i_value = *b2;
  1238. X           int in = now-1; while (in--)
  1239. X           {
  1240. X          // it should be possible to make this faster
  1241. X          // hand code for now = 2,3,4,5,8
  1242. X          // use symmetry to halve number of operations
  1243. X          a2 -= gamma; b2 -= gamma;  Real temp = r_value;
  1244. X          r_value = r_value * r_arg - i_value * i_arg + *a2;
  1245. X          i_value = temp    * i_arg + i_value * r_arg + *b2;
  1246. X           }
  1247. X           *x2 = r_value; *y2 = i_value;   x2 += delta; y2 += delta;
  1248. X        }
  1249. X     }
  1250. X
  1251. X         // temp = r_arg;
  1252. X         // r_arg = r_arg * r_omega - i_arg * i_omega;
  1253. X         // i_arg = temp  * i_omega + i_arg * r_omega;
  1254. X
  1255. X      }
  1256. X   }
  1257. X}
  1258. X
  1259. X
  1260. Xvoid FFT(const ColumnVector& U, const ColumnVector& V,
  1261. X   ColumnVector& X, ColumnVector& Y)
  1262. X{
  1263. X   // from Carl de Boor (1980), Siam J Sci Stat Comput, 1 173-8
  1264. X   Tracer trace("FFT");
  1265. X   const int n = U.Nrows();                     // length of arrays
  1266. X   if (n != V.Nrows() || n == 0)
  1267. X      Throw(ProgramException("Vector lengths unequal or zero", U, V));
  1268. X   ColumnVector A = U; ColumnVector B = V;
  1269. X   X.ReDimension(n); Y.ReDimension(n);
  1270. X   const int nextmx = 8;
  1271. X#ifndef ATandT
  1272. X   int prime[8] = { 2,3,5,7,11,13,17,19 };
  1273. X#else
  1274. X   int prime[8];
  1275. X   prime[0]=2; prime[1]=3; prime[2]=5; prime[3]=7;
  1276. X   prime[4]=11; prime[5]=13; prime[6]=17; prime[7]=19;
  1277. X#endif
  1278. X   int after = 1; int before = n; int next = 0; Boolean inzee = TRUE;
  1279. X
  1280. X   do
  1281. X   {
  1282. X      int now, b1;
  1283. X      for (;;)
  1284. X      {
  1285. X     if (next < nextmx) now = prime[next];
  1286. X     b1 = before / now;  if (b1 * now == before) break;
  1287. X     next++; now += 2;
  1288. X      }
  1289. X      before = b1;
  1290. X
  1291. X      if (inzee) fftstep(A, B, X, Y, after, now, before);
  1292. X      else fftstep(X, Y, A, B, after, now, before);
  1293. X
  1294. X      inzee = !inzee; after *= now;
  1295. X   }
  1296. X   while (before != 1);
  1297. X
  1298. X   if (inzee) { A.Release(); X = A; B.Release(); Y = B; }
  1299. X}
  1300. X
  1301. X
  1302. Xvoid FFTI(const ColumnVector& U, const ColumnVector& V,
  1303. X   ColumnVector& X, ColumnVector& Y)
  1304. X{
  1305. X   // Inverse transform
  1306. X   Tracer trace("FFTI");
  1307. X   FFT(U,-V,X,Y);
  1308. X   const Real n = X.Nrows(); X = X / n; Y = Y / (-n);
  1309. X}
  1310. X
  1311. Xvoid RealFFT(const ColumnVector& U, ColumnVector& X, ColumnVector& Y)
  1312. X{
  1313. X   // Fourier transform of a real series
  1314. X   Tracer trace("RealFFT");
  1315. X   const int n = U.Nrows();                     // length of arrays
  1316. X   const int n2 = n / 2;
  1317. X   if (n != 2 * n2)
  1318. X      Throw(ProgramException("Vector length not multiple of 2", U));
  1319. X   ColumnVector A(n2), B(n2);
  1320. X   Real* a = A.Store(); Real* b = B.Store(); Real* u = U.Store(); int i = n2;
  1321. X   while (i--) { *a++ = *u++; *b++ = *u++; }
  1322. X   FFT(A,B,A,B);
  1323. X   int n21 = n2 + 1;
  1324. X   X.ReDimension(n21); Y.ReDimension(n21);
  1325. X   i = n2 - 1;
  1326. X   a = A.Store(); b = B.Store();              // first els of A and B
  1327. X   Real* an = a + i; Real* bn = b + i;        // last els of A and B
  1328. X   Real* x = X.Store(); Real* y = Y.Store();  // first els of X and Y
  1329. X   Real* xn = x + n2; Real* yn = y + n2;      // last els of X and Y
  1330. X
  1331. X   *x++ = *a + *b; *y++ = 0.0;                // first complex element
  1332. X   *xn-- = *a++ - *b++; *yn-- = 0.0;          // last complex element
  1333. X
  1334. X   int j = -1; i = n2/2;
  1335. X   while (i--)
  1336. X   {
  1337. X      Real c,s; cossin(j--,n,c,s);
  1338. X      Real am = *a - *an; Real ap = *a++ + *an--;
  1339. X      Real bm = *b - *bn; Real bp = *b++ + *bn--;
  1340. X      Real samcbp = s * am + c * bp; Real sbpcam = s * bp - c * am;
  1341. X      *x++  =  0.5 * ( ap + samcbp); *y++  =  0.5 * ( bm + sbpcam);
  1342. X      *xn-- =  0.5 * ( ap - samcbp); *yn-- =  0.5 * (-bm + sbpcam);
  1343. X   }
  1344. X}
  1345. X
  1346. Xvoid RealFFTI(const ColumnVector& A, const ColumnVector& B, ColumnVector& U)
  1347. X{
  1348. X   // inverse of a Fourier transform of a real series
  1349. X   Tracer trace("RealFFTI");
  1350. X   const int n21 = A.Nrows();                     // length of arrays
  1351. X   if (n21 != B.Nrows() || n21 == 0)
  1352. X      Throw(ProgramException("Vector lengths unequal or zero", A, B));
  1353. X   const int n2 = n21 - 1;  const int n = 2 * n2;  int i = n2 - 1;
  1354. X
  1355. X   ColumnVector X(n2), Y(n2);
  1356. X   Real* a = A.Store(); Real* b = B.Store();  // first els of A and B
  1357. X   Real* an = a + n2;   Real* bn = b + n2;    // last els of A and B
  1358. X   Real* x = X.Store(); Real* y = Y.Store();  // first els of X and Y
  1359. X   Real* xn = x + i;    Real* yn = y + i;     // last els of X and Y
  1360. X
  1361. X   Real hn = 0.5 / n2;
  1362. X   *x++  = hn * (*a + *an);  *y++  = - hn * (*a - *an);
  1363. X   a++; an--; b++; bn--;
  1364. X   int j = -1;  i = n2/2;
  1365. X   while (i--)
  1366. X   {
  1367. X      Real c,s; cossin(j--,n,c,s);
  1368. X      Real am = *a - *an; Real ap = *a++ + *an--;
  1369. X      Real bm = *b - *bn; Real bp = *b++ + *bn--;
  1370. X      Real samcbp = s * am - c * bp; Real sbpcam = s * bp + c * am;
  1371. X      *x++  =  hn * ( ap + samcbp); *y++  =  - hn * ( bm + sbpcam);
  1372. X      *xn-- =  hn * ( ap - samcbp); *yn-- =  - hn * (-bm + sbpcam);
  1373. X   }
  1374. X   FFT(X,Y,X,Y);             // have done inverting elsewhere
  1375. X   U.ReDimension(n); i = n2;
  1376. X   x = X.Store(); y = Y.Store(); Real* u = U.Store();
  1377. X   while (i--) { *u++ = *x++; *u++ = - *y++; }
  1378. X}
  1379. X
  1380. END_OF_FILE
  1381. if test 7012 -ne `wc -c <'fft.cxx'`; then
  1382.     echo shar: \"'fft.cxx'\" unpacked with wrong size!
  1383. fi
  1384. # end of 'fft.cxx'
  1385. fi
  1386. if test -f 'hholder.cxx' -a "${1}" != "-c" ; then 
  1387.   echo shar: Will not clobber existing file \"'hholder.cxx'\"
  1388. else
  1389. echo shar: Extracting \"'hholder.cxx'\" \(1555 characters\)
  1390. sed "s/^X//" >'hholder.cxx' <<'END_OF_FILE'
  1391. X//$$ hholder.cxx                       Householder triangularisation
  1392. X
  1393. X// Copyright (C) 1991,2,3: R B Davies
  1394. X
  1395. X#define WANT_MATH
  1396. X
  1397. X#include "include.h"
  1398. X
  1399. X#include "newmatap.h"
  1400. X
  1401. X
  1402. X/********************** householder triangularisation *********************/
  1403. X
  1404. Xinline Real square(Real x) { return x*x; }
  1405. X
  1406. Xvoid HHDecompose(Matrix& X, LowerTriangularMatrix& L)
  1407. X{
  1408. X   Tracer et("HHDecompose(1)");
  1409. X   int n = X.Ncols(); int s = X.Nrows(); L.ReDimension(s);
  1410. X   Real* xi = X.Store(); int k;
  1411. X   for (int i=0; i<s; i++)
  1412. X   {
  1413. X      Real sum = 0.0;
  1414. X      Real* xi0=xi; k=n; while(k--) { sum += square(*xi++); }
  1415. X      sum = sqrt(sum);
  1416. X      L.element(i,i) = sum;
  1417. X      if (sum==0.0) Throw(SingularException(L));
  1418. X      Real* xj0=xi0; k=n; while(k--) { *xj0++ /= sum; }
  1419. X      for (int j=i+1; j<s; j++)
  1420. X      {
  1421. X         sum=0.0;
  1422. X     xi=xi0; Real* xj=xj0; k=n; while(k--) { sum += *xi++ * *xj++; }
  1423. X     xi=xi0; k=n; while(k--) { *xj0++ -= sum * *xi++; }
  1424. X     L.element(j,i) = sum;
  1425. X      }
  1426. X   }
  1427. X}
  1428. X
  1429. Xvoid HHDecompose(const Matrix& X, Matrix& Y, Matrix& M)
  1430. X{
  1431. X   Tracer et("HHDecompose(1)");
  1432. X   int n = X.Ncols(); int s = X.Nrows(); int t = Y.Nrows();
  1433. X   if (Y.Ncols() != n)
  1434. X   { Throw(ProgramException("Unequal row lengths",X,Y)); }
  1435. X   M.ReDimension(t,s);
  1436. X   Real* xi = X.Store(); int k;
  1437. X   for (int i=0; i<s; i++)
  1438. X   {
  1439. X      Real* xj0 = Y.Store(); Real* xi0 = xi;
  1440. X      for (int j=0; j<t; j++)
  1441. X      {
  1442. X         Real sum=0.0;
  1443. X         xi=xi0; Real* xj=xj0; k=n; while(k--) { sum += *xi++ * *xj++; }
  1444. X     xi=xi0; k=n; while(k--) { *xj0++ -= sum * *xi++; }
  1445. X     M.element(j,i) = sum;
  1446. X      }
  1447. X   }
  1448. X}
  1449. X
  1450. END_OF_FILE
  1451. if test 1555 -ne `wc -c <'hholder.cxx'`; then
  1452.     echo shar: \"'hholder.cxx'\" unpacked with wrong size!
  1453. fi
  1454. # end of 'hholder.cxx'
  1455. fi
  1456. if test -f 'jacobi.cxx' -a "${1}" != "-c" ; then 
  1457.   echo shar: Will not clobber existing file \"'jacobi.cxx'\"
  1458. else
  1459. echo shar: Extracting \"'jacobi.cxx'\" \(2874 characters\)
  1460. sed "s/^X//" >'jacobi.cxx' <<'END_OF_FILE'
  1461. X//$$jacobi.cxx                           jacobi eigenvalue analysis
  1462. X
  1463. X// Copyright (C) 1991,2,3: R B Davies
  1464. X
  1465. X
  1466. X#define WANT_STREAM
  1467. X
  1468. X
  1469. X#define WANT_MATH
  1470. X
  1471. X#include "include.h"
  1472. X#include "newmat.h"
  1473. X#include "precisio.h"
  1474. X#include "newmatrm.h"
  1475. X
  1476. X
  1477. X
  1478. Xvoid Jacobi(const SymmetricMatrix& X, DiagonalMatrix& D, SymmetricMatrix& A,
  1479. X   Matrix& V, Boolean eivec)
  1480. X{
  1481. X   Real epsilon = FloatingPointPrecision::Epsilon();
  1482. X   Tracer et("Jacobi");
  1483. X   int n = X.Nrows(); DiagonalMatrix B(n), Z(n); D.ReDimension(n); A = X;
  1484. X   if (eivec) { V.ReDimension(n,n); D = 1.0; V = D; }
  1485. X   B << A; D = B; Z = 0.0; A.Inject(Z);
  1486. X   for (int i=1; i<=50; i++)
  1487. X   {
  1488. X      Real sm=0.0; Real* a = A.Store(); int p = A.Storage();
  1489. X      while (p--) sm += fabs(*a++);            // have previously zeroed diags
  1490. X      if (sm==0.0) return;
  1491. X      Real tresh = (i<4) ? 0.2 * sm / square(n) : 0.0; a = A.Store();
  1492. X      for (p = 0; p < n; p++)
  1493. X      {
  1494. X     Real* ap1 = a + (p*(p+1))/2;
  1495. X         Real& zp = Z.element(p); Real& dp = D.element(p);
  1496. X     for (int q = p+1; q < n; q++)
  1497. X     {
  1498. X        Real* ap = ap1; Real* aq = a + (q*(q+1))/2;
  1499. X            Real& zq = Z.element(q); Real& dq = D.element(q);
  1500. X            Real& apq = A.element(q,p);
  1501. X            Real g = 100 * fabs(apq); Real adp = fabs(dp); Real adq = fabs(dq);
  1502. X
  1503. X        if (i>4 && g < epsilon*adp && g < epsilon*adq) apq = 0.0;
  1504. X        else if (fabs(apq) > tresh)
  1505. X        {
  1506. X           Real t; Real h = dq - dp; Real ah = fabs(h);
  1507. X           if (g < epsilon*ah) t = apq / h;
  1508. X           else
  1509. X           {
  1510. X          Real theta = 0.5 * h / apq;
  1511. X          t = 1.0 / ( fabs(theta) + sqrt(1.0 + square(theta)) );
  1512. X          if (theta<0.0) t = -t;
  1513. X           }
  1514. X           Real c = 1.0 / sqrt(1.0 + square(t)); Real s = t * c;
  1515. X           Real tau = s / (1.0 + c); h = t * apq;
  1516. X               zp -= h; zq += h; dp -= h; dq += h; apq = 0.0;
  1517. X           int j = p;
  1518. X           while (j--)
  1519. X           {
  1520. X          g = *ap; h = *aq;
  1521. X          *ap++ = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
  1522. X           }
  1523. X           int ip = p+1; j = q-ip; ap += ip++; aq++;
  1524. X           while (j--)
  1525. X           {
  1526. X          g = *ap; h = *aq;
  1527. X                  *ap = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
  1528. X          ap += ip++;
  1529. X           }
  1530. X           int iq = q+1; j = n-iq; ap += ip++; aq += iq++;
  1531. X           while (j--)
  1532. X           {
  1533. X          g = *ap; h = *aq;
  1534. X          *ap = g-s*(h+g*tau); *aq = h+s*(g-h*tau);
  1535. X          ap += ip++; aq += iq++;
  1536. X           }
  1537. X           if (eivec)
  1538. X           {
  1539. X                  RectMatrixCol VP(V,p); RectMatrixCol VQ(V,q);
  1540. X                  Rotate(VP, VQ, tau, s);
  1541. X           }
  1542. X        }
  1543. X     }
  1544. X      }
  1545. X      B = B + Z; D = B; Z = 0.0;
  1546. X   }
  1547. X   Throw(ConvergenceException(X));
  1548. X}
  1549. X
  1550. Xvoid Jacobi(const SymmetricMatrix& X, DiagonalMatrix& D)
  1551. X{ SymmetricMatrix A; Matrix V; Jacobi(X,D,A,V,FALSE); }
  1552. X
  1553. Xvoid Jacobi(const SymmetricMatrix& X, DiagonalMatrix& D, SymmetricMatrix& A)
  1554. X{ Matrix V; Jacobi(X,D,A,V,FALSE); }
  1555. X
  1556. Xvoid Jacobi(const SymmetricMatrix& X, DiagonalMatrix& D, Matrix& V)
  1557. X{ SymmetricMatrix A; Jacobi(X,D,A,V,TRUE); }
  1558. X
  1559. X
  1560. END_OF_FILE
  1561. if test 2874 -ne `wc -c <'jacobi.cxx'`; then
  1562.     echo shar: \"'jacobi.cxx'\" unpacked with wrong size!
  1563. fi
  1564. # end of 'jacobi.cxx'
  1565. fi
  1566. if test -f 'sort.cxx' -a "${1}" != "-c" ; then 
  1567.   echo shar: Will not clobber existing file \"'sort.cxx'\"
  1568. else
  1569. echo shar: Extracting \"'sort.cxx'\" \(1370 characters\)
  1570. sed "s/^X//" >'sort.cxx' <<'END_OF_FILE'
  1571. X//$$ sort.cxx                            Sorting
  1572. X
  1573. X// Copyright (C) 1991,2,3: R B Davies
  1574. X
  1575. X#define WANT_MATH
  1576. X
  1577. X#include "include.h"
  1578. X
  1579. X#include "newmatap.h"
  1580. X
  1581. X
  1582. X/******************************** Shell sort ********************************/
  1583. X
  1584. Xvoid SortAscending(GeneralMatrix& GM)
  1585. X{
  1586. X   // from numerical recipies in C - Shell sort
  1587. X   Tracer et("Sort-ascending");
  1588. X
  1589. X   const double aln2i = 1.442695022; const double tiny = 1.0e-5;
  1590. X   Real* gm = GM.Store(); int n = GM.Storage(); int m = n;
  1591. X   int lognb2 = (int)(aln2i * log((double)n) + tiny);
  1592. X   while (lognb2--)
  1593. X   {
  1594. X      m >>= 1;
  1595. X      for (int j = m; j<n; j++)
  1596. X      {
  1597. X         Real* gmj = gm+j; int i = j-m; Real* gmi = gmj-m; Real t = *gmj;
  1598. X         while (i>=0 && *gmi>t)  { *gmj = *gmi; gmj = gmi; gmi -= m; i -= m; }
  1599. X         *gmj = t;
  1600. X      }
  1601. X   }
  1602. X}
  1603. X
  1604. Xvoid SortDescending(GeneralMatrix& GM)
  1605. X{
  1606. X   // from numerical recipies in C - Shell sort
  1607. X   Tracer et("Sort-descending");
  1608. X
  1609. X   const double aln2i = 1.442695022; const double tiny = 1.0e-5;
  1610. X   Real* gm = GM.Store(); int n = GM.Storage(); int m = n;
  1611. X   int lognb2 = (int)(aln2i * log((double)n) + tiny);
  1612. X   while (lognb2--)
  1613. X   {
  1614. X      m >>= 1;
  1615. X      for (int j = m; j<n; j++)
  1616. X      {
  1617. X         Real* gmj = gm+j; int i = j-m; Real* gmi = gmj-m; Real t = *gmj;
  1618. X         while (i>=0 && *gmi<t)  { *gmj = *gmi; gmj = gmi; gmi -= m; i -= m; }
  1619. X         *gmj = t;
  1620. X      }
  1621. X   }
  1622. X}
  1623. X
  1624. END_OF_FILE
  1625. if test 1370 -ne `wc -c <'sort.cxx'`; then
  1626.     echo shar: \"'sort.cxx'\" unpacked with wrong size!
  1627. fi
  1628. # end of 'sort.cxx'
  1629. fi
  1630. if test -f 'submat.cxx' -a "${1}" != "-c" ; then 
  1631.   echo shar: Will not clobber existing file \"'submat.cxx'\"
  1632. else
  1633. echo shar: Extracting \"'submat.cxx'\" \(7581 characters\)
  1634. sed "s/^X//" >'submat.cxx' <<'END_OF_FILE'
  1635. X//$$ submat.cxx                         submatrices
  1636. X
  1637. X// Copyright (C) 1991,2,3: R B Davies
  1638. X
  1639. X#include "include.h"
  1640. X
  1641. X#include "newmat.h"
  1642. X#include "newmatrc.h"
  1643. X
  1644. X
  1645. X//#define REPORT { static ExeCounter ExeCount(__LINE__,6); ExeCount++; }
  1646. X
  1647. X#define REPORT {}
  1648. X
  1649. X
  1650. X/****************************** submatrices *********************************/
  1651. X
  1652. X#ifdef TEMPS_DESTROYED_QUICKLY
  1653. XGetSubMatrix& BaseMatrix::SubMatrix(int first_row, int last_row, int first_col,
  1654. X   int last_col) const
  1655. X#else
  1656. XGetSubMatrix BaseMatrix::SubMatrix(int first_row, int last_row, int first_col,
  1657. X   int last_col) const
  1658. X#endif
  1659. X{
  1660. X   REPORT
  1661. X   Tracer tr("SubMatrix");
  1662. X   int a = first_row - 1; int b = last_row - first_row + 1;
  1663. X   int c = first_col - 1; int d = last_col - first_col + 1;
  1664. X   if (a<0 || b<=0 || c<0 || d<=0) Throw(SubMatrixDimensionException());
  1665. X#ifdef TEMPS_DESTROYED_QUICKLY
  1666. X   GetSubMatrix* x = new GetSubMatrix(this, a, b, c, d, FALSE);
  1667. X   MatrixErrorNoSpace(x);
  1668. X   return *x;
  1669. X#else
  1670. X   return GetSubMatrix(this, a, b, c, d, FALSE);
  1671. X#endif
  1672. X}
  1673. X
  1674. X#ifdef TEMPS_DESTROYED_QUICKLY
  1675. XGetSubMatrix& BaseMatrix::SymSubMatrix(int first_row, int last_row) const
  1676. X#else
  1677. XGetSubMatrix BaseMatrix::SymSubMatrix(int first_row, int last_row) const
  1678. X#endif
  1679. X{
  1680. X   REPORT
  1681. X   Tracer tr("SubMatrix(symmetric)");
  1682. X   int a = first_row - 1; int b = last_row - first_row + 1;
  1683. X   if (a<0 || b<=0) Throw(SubMatrixDimensionException());
  1684. X#ifdef TEMPS_DESTROYED_QUICKLY
  1685. X   GetSubMatrix* x = new GetSubMatrix(this, a, b, a, b, TRUE);
  1686. X   MatrixErrorNoSpace(x);
  1687. X   return *x;
  1688. X#else
  1689. X   return GetSubMatrix( this, a, b, a, b, TRUE);
  1690. X#endif
  1691. X}
  1692. X
  1693. X#ifdef TEMPS_DESTROYED_QUICKLY
  1694. XGetSubMatrix& BaseMatrix::Row(int first_row) const
  1695. X#else
  1696. XGetSubMatrix BaseMatrix::Row(int first_row) const
  1697. X#endif
  1698. X{
  1699. X   REPORT
  1700. X   Tracer tr("SubMatrix(row)");
  1701. X   int a = first_row - 1;
  1702. X   if (a<0) Throw(SubMatrixDimensionException());
  1703. X#ifdef TEMPS_DESTROYED_QUICKLY
  1704. X   GetSubMatrix* x = new GetSubMatrix(this, a, 1, 0, -1, FALSE);
  1705. X   MatrixErrorNoSpace(x);
  1706. X   return *x;
  1707. X#else
  1708. X   return GetSubMatrix(this, a, 1, 0, -1, FALSE);
  1709. X#endif
  1710. X}
  1711. X
  1712. X#ifdef TEMPS_DESTROYED_QUICKLY
  1713. XGetSubMatrix& BaseMatrix::Rows(int first_row, int last_row) const
  1714. X#else
  1715. XGetSubMatrix BaseMatrix::Rows(int first_row, int last_row) const
  1716. X#endif
  1717. X{
  1718. X   REPORT
  1719. X   Tracer tr("SubMatrix(rows)");
  1720. X   int a = first_row - 1; int b = last_row - first_row + 1;
  1721. X   if (a<0 || b<=0) Throw(SubMatrixDimensionException());
  1722. X#ifdef TEMPS_DESTROYED_QUICKLY
  1723. X   GetSubMatrix* x = new GetSubMatrix(this, a, b, 0, -1, FALSE);
  1724. X   MatrixErrorNoSpace(x);
  1725. X   return *x;
  1726. X#else
  1727. X   return GetSubMatrix(this, a, b, 0, -1, FALSE);
  1728. X#endif
  1729. X}
  1730. X
  1731. X#ifdef TEMPS_DESTROYED_QUICKLY
  1732. XGetSubMatrix& BaseMatrix::Column(int first_col) const
  1733. X#else
  1734. XGetSubMatrix BaseMatrix::Column(int first_col) const
  1735. X#endif
  1736. X{
  1737. X   REPORT
  1738. X   Tracer tr("SubMatrix(column)");
  1739. X   int c = first_col - 1;
  1740. X   if (c<0) Throw(SubMatrixDimensionException());
  1741. X#ifdef TEMPS_DESTROYED_QUICKLY
  1742. X   GetSubMatrix* x = new GetSubMatrix(this, 0, -1, c, 1, FALSE);
  1743. X   MatrixErrorNoSpace(x);
  1744. X   return *x;
  1745. X#else
  1746. X   return GetSubMatrix(this, 0, -1, c, 1, FALSE);
  1747. X#endif
  1748. X}
  1749. X
  1750. X#ifdef TEMPS_DESTROYED_QUICKLY
  1751. XGetSubMatrix& BaseMatrix::Columns(int first_col, int last_col) const
  1752. X#else
  1753. XGetSubMatrix BaseMatrix::Columns(int first_col, int last_col) const
  1754. X#endif
  1755. X{
  1756. X   REPORT
  1757. X   Tracer tr("SubMatrix(columns)");
  1758. X   int c = first_col - 1; int d = last_col - first_col + 1;
  1759. X   if (c<0 || d<=0) Throw(SubMatrixDimensionException());
  1760. X#ifdef TEMPS_DESTROYED_QUICKLY
  1761. X   GetSubMatrix* x = new GetSubMatrix(this, 0, -1, c, d, FALSE);
  1762. X   MatrixErrorNoSpace(x);
  1763. X   return *x;
  1764. X#else
  1765. X   return GetSubMatrix(this, 0, -1, c, d, FALSE);
  1766. X#endif
  1767. X}
  1768. X
  1769. Xvoid GetSubMatrix::SetUpLHS()
  1770. X{
  1771. X   REPORT
  1772. X   Tracer tr("SubMatrix(LHS)");
  1773. X   const BaseMatrix* bm1 = bm;
  1774. X   GeneralMatrix* gm = ((BaseMatrix*&)bm)->Evaluate();
  1775. X   if ((BaseMatrix*)gm!=bm1)
  1776. X      Throw(ProgramException("Invalid LHS"));
  1777. X   if (row_number < 0) row_number = gm->Nrows();
  1778. X   if (col_number < 0) col_number = gm->Ncols();
  1779. X   if (row_skip+row_number > gm->Nrows() || col_skip+col_number > gm->Ncols())
  1780. X      Throw(SubMatrixDimensionException());
  1781. X}
  1782. X
  1783. Xvoid GetSubMatrix::operator<<(const BaseMatrix& bmx)
  1784. X{
  1785. X   REPORT
  1786. X   Tracer tr("SubMatrix(<<)"); GeneralMatrix* gmx = 0;
  1787. X   Try
  1788. X   {
  1789. X      SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate();
  1790. X      if (row_number != gmx->Nrows() || col_number != gmx->Ncols())
  1791. X         Throw(IncompatibleDimensionsException());
  1792. X      MatrixRow mrx(gmx, LoadOnEntry); 
  1793. X      MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
  1794. X                                     // do need LoadOnEntry
  1795. X      MatrixRowCol sub; int i = row_number;
  1796. X      while (i--)
  1797. X      {
  1798. X         mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
  1799. X         sub.Copy(mrx); mr.Next(); mrx.Next();
  1800. X      }
  1801. X      gmx->tDelete();
  1802. X#ifdef TEMPS_DESTROYED_QUICKLY
  1803. X      delete this;
  1804. X#endif
  1805. X   }   
  1806. X
  1807. X   CatchAll
  1808. X   {
  1809. X      if (gmx) gmx->tDelete();
  1810. X#ifdef TEMPS_DESTROYED_QUICKLY
  1811. X      delete this;
  1812. X#endif
  1813. X      Throw();
  1814. X   }
  1815. X}
  1816. X
  1817. Xvoid GetSubMatrix::operator=(const BaseMatrix& bmx)
  1818. X{
  1819. X   REPORT
  1820. X   Tracer tr("SubMatrix(=)"); GeneralMatrix* gmx = 0;
  1821. X   MatrixConversionCheck mcc;         // Check for loss of info
  1822. X   Try
  1823. X   {
  1824. X      SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate();
  1825. X      if (row_number != gmx->Nrows() || col_number != gmx->Ncols())
  1826. X         Throw(IncompatibleDimensionsException());
  1827. X      MatrixRow mrx(gmx, LoadOnEntry); 
  1828. X      MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
  1829. X                                     // do need LoadOnEntry
  1830. X      MatrixRowCol sub; int i = row_number;
  1831. X      while (i--)
  1832. X      {
  1833. X         mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
  1834. X         sub.CopyCheck(mrx); mr.Next(); mrx.Next();
  1835. X      }
  1836. X      gmx->tDelete();
  1837. X#ifdef TEMPS_DESTROYED_QUICKLY
  1838. X      delete this;
  1839. X#endif
  1840. X   }   
  1841. X
  1842. X   CatchAll
  1843. X   {
  1844. X      if (gmx) gmx->tDelete();
  1845. X#ifdef TEMPS_DESTROYED_QUICKLY
  1846. X      delete this;
  1847. X#endif
  1848. X      Throw();
  1849. X   }
  1850. X}
  1851. X
  1852. Xvoid GetSubMatrix::operator<<(const Real* r)
  1853. X{
  1854. X   REPORT
  1855. X   Tracer tr("SubMatrix(<<Real*)");
  1856. X   SetUpLHS();
  1857. X   if (row_skip+row_number > gm->Nrows() || col_skip+col_number > gm->Ncols())
  1858. X      Throw(SubMatrixDimensionException());
  1859. X   MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
  1860. X                                  // do need LoadOnEntry
  1861. X   MatrixRowCol sub; int i = row_number;
  1862. X   while (i--)
  1863. X   {
  1864. X      mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
  1865. X      sub.Copy(r); mr.Next();
  1866. X   }
  1867. X#ifdef TEMPS_DESTROYED_QUICKLY
  1868. X   delete this;
  1869. X#endif
  1870. X}   
  1871. X
  1872. Xvoid GetSubMatrix::operator=(Real r)
  1873. X{
  1874. X   REPORT
  1875. X   Tracer tr("SubMatrix(=Real)");
  1876. X   SetUpLHS();
  1877. X   MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
  1878. X                                  // do need LoadOnEntry
  1879. X   MatrixRowCol sub; int i = row_number;
  1880. X   while (i--)
  1881. X   {
  1882. X      mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
  1883. X      sub.Copy(r); mr.Next();
  1884. X   }
  1885. X#ifdef TEMPS_DESTROYED_QUICKLY
  1886. X   delete this;
  1887. X#endif
  1888. X}   
  1889. X
  1890. Xvoid GetSubMatrix::Inject(const GeneralMatrix& gmx)
  1891. X{
  1892. X   REPORT
  1893. X   Tracer tr("SubMatrix(inject)");
  1894. X   SetUpLHS();
  1895. X   if (row_number != gmx.Nrows() || col_number != gmx.Ncols())
  1896. X      Throw(IncompatibleDimensionsException());
  1897. X   MatrixRow mrx((GeneralMatrix*)(&gmx), LoadOnEntry);
  1898. X   MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
  1899. X                                  // do need LoadOnEntry
  1900. X   MatrixRowCol sub; int i = row_number;
  1901. X   while (i--)
  1902. X   {
  1903. X      mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
  1904. X      sub.Inject(mrx); mr.Next(); mrx.Next();
  1905. X   }
  1906. X#ifdef TEMPS_DESTROYED_QUICKLY
  1907. X   delete this;
  1908. X#endif
  1909. X}
  1910. X
  1911. END_OF_FILE
  1912. if test 7581 -ne `wc -c <'submat.cxx'`; then
  1913.     echo shar: \"'submat.cxx'\" unpacked with wrong size!
  1914. fi
  1915. # end of 'submat.cxx'
  1916. fi
  1917. if test -f 'svd.cxx' -a "${1}" != "-c" ; then 
  1918.   echo shar: Will not clobber existing file \"'svd.cxx'\"
  1919. else
  1920. echo shar: Extracting \"'svd.cxx'\" \(4482 characters\)
  1921. sed "s/^X//" >'svd.cxx' <<'END_OF_FILE'
  1922. X//$$svd.cxx                           singular value decomposition
  1923. X
  1924. X// Copyright (C) 1991,2,3: R B Davies
  1925. X
  1926. X#define WANT_MATH
  1927. X
  1928. X#include "include.h"
  1929. X#include "newmat.h"
  1930. X#include "newmatrm.h"
  1931. X#include "precisio.h"
  1932. X
  1933. X
  1934. Xvoid SVD(const Matrix& A, DiagonalMatrix& Q, Matrix& U, Matrix& V,
  1935. X   Boolean withU, Boolean withV)
  1936. X// from Wilkinson and Reinsch: "Handbook of Automatic Computation"
  1937. X{
  1938. X   Tracer trace("SVD");
  1939. X   Real eps = FloatingPointPrecision::Epsilon();
  1940. X   Real tol = FloatingPointPrecision::Minimum()/eps;
  1941. X
  1942. X   int m = A.Nrows(); int n = A.Ncols();
  1943. X   if (m<n) 
  1944. X      Throw(ProgramException("Want no. Rows >= no. Cols", A));
  1945. X
  1946. X   U = A; Real g = 0.0; Real f,h; Real x = 0.0;
  1947. X   RowVector E(n); RectMatrixRow EI(E,0); Q.ReDimension(n);
  1948. X   RectMatrixCol UCI(U,0); RectMatrixRow URI(U,0,1,n-1);
  1949. X
  1950. X   for (int i=0; i<n; i++)
  1951. X   {
  1952. X      EI.First() = g; Real ei = g; EI.Right(); Real s = UCI.SumSquare();
  1953. X      if (s<tol) Q.element(i) = 0.0;
  1954. X      else
  1955. X      {
  1956. X     f = UCI.First(); g = -sign(sqrt(s), f); h = f*g-s; UCI.First() = f-g;
  1957. X     Q.element(i) = g; RectMatrixCol UCJ = UCI; int j=n-i;
  1958. X     while (--j) { UCJ.Right(); UCJ.AddScaled(UCI, (UCI*UCJ)/h); }
  1959. X      }
  1960. X
  1961. X      s = URI.SumSquare();
  1962. X      if (s<tol) g = 0.0;
  1963. X      else
  1964. X      {
  1965. X     f = URI.First(); g = -sign(sqrt(s), f); URI.First() = f-g;
  1966. X     EI.Divide(URI,f*g-s); RectMatrixRow URJ = URI; int j=m-i;
  1967. X     while (--j) { URJ.Down(); URJ.AddScaled(EI, URI*URJ); }
  1968. X      }
  1969. X
  1970. X      Real y = fabs(Q.element(i)) + fabs(ei); if (x<y) x = y;
  1971. X      UCI.DownDiag(); URI.DownDiag();
  1972. X   }
  1973. X
  1974. X   if (withV)
  1975. X   {
  1976. X      V.ReDimension(n,n); V = 0.0; RectMatrixCol VCI(V,n,n,0);
  1977. X      for (i=n-1; i>=0; i--)
  1978. X      {
  1979. X     URI.UpDiag(); VCI.Left();
  1980. X     if (g!=0.0)
  1981. X     {
  1982. X        VCI.Divide(URI, URI.First()*g); int j = n-i;
  1983. X        RectMatrixCol VCJ = VCI;
  1984. X        while (--j) { VCJ.Right(); VCJ.AddScaled( VCI, (URI*VCJ) ); }
  1985. X     }
  1986. X     VCI.Zero(); VCI.Up(); VCI.First() = 1.0; g=E.element(i);
  1987. X      }
  1988. X   }
  1989. X
  1990. X   if (withU)
  1991. X   {
  1992. X      for (i=n-1; i>=0; i--)
  1993. X      {
  1994. X     UCI.UpDiag(); g = Q.element(i); URI.Reset(U,i,i+1,n-i-1); URI.Zero();
  1995. X         if (g!=0.0)
  1996. X         {
  1997. X        h=UCI.First()*g; int j=n-i; RectMatrixCol UCJ = UCI;
  1998. X        while (--j)
  1999. X            {
  2000. X           UCJ.Right(); UCI.Down(); UCJ.Down(); Real s = UCI*UCJ;
  2001. X               UCI.Up(); UCJ.Up(); UCJ.AddScaled(UCI,s/h);
  2002. X            }
  2003. X        UCI.Divide(g);
  2004. X         }
  2005. X         else UCI.Zero();
  2006. X         UCI.First() += 1.0;
  2007. X      }
  2008. X   }
  2009. X
  2010. X   eps *= x;
  2011. X   for (int k=n-1; k>=0; k--)
  2012. X   {
  2013. X      Real z; Real y; int limit = 50; int l;
  2014. X      while (limit--)
  2015. X      {
  2016. X     Real c=0.0; Real s=1.0; int i; int l1=k; Boolean tfc=FALSE;
  2017. X     for (l=k; l>=0; l--)
  2018. X     {
  2019. X//          if (fabs(E.element(l))<=eps) goto test_f_convergence;
  2020. X        if (fabs(E.element(l))<=eps) { tfc=TRUE; break; }
  2021. X        if (fabs(Q.element(l-1))<=eps) { l1=l; break; }
  2022. X     }
  2023. X         if (!tfc)
  2024. X         {
  2025. X        l=l1; l1=l-1;
  2026. X        for (i=l; i<=k; i++)
  2027. X        {
  2028. X           f = s * E.element(i); E.element(i) *= c;
  2029. X//             if (fabs(f)<=eps) goto test_f_convergence;
  2030. X           if (fabs(f)<=eps) break;
  2031. X           g = Q.element(i); h = sqrt(f*f + g*g); Q.element(i) = h;
  2032. X           if (withU)
  2033. X           {
  2034. X              RectMatrixCol UCI(U,i); RectMatrixCol UCJ(U,l1);
  2035. X              ComplexScale(UCI, UCJ, g/h, -f/h);
  2036. X               }
  2037. X            }
  2038. X     }
  2039. X//    test_f_convergence: z = Q.element(k); if (l==k) goto convergence;
  2040. X     z = Q.element(k);  if (l==k) break;
  2041. X
  2042. X     x = Q.element(l); y = Q.element(k-1);
  2043. X     g = E.element(k-1); h = E.element(k);
  2044. X     f = ((y-z)*(y+z) + (g-h)*(g+h)) / (2*h*y); g = sqrt(f*f + 1);
  2045. X     f = ((x-z)*(x+z) + h*(y / ((f<0.0) ? f-g : f+g)-h)) / x;
  2046. X
  2047. X     c = 1.0; s = 1.0;
  2048. X     for (i=l+1; i<=k; i++)
  2049. X     {
  2050. X        g = E.element(i); y = Q.element(i); h = s*g; g *= c;
  2051. X        z = sqrt(f*f + h*h); E.element(i-1) = z; c = f/z; s = h/z;
  2052. X        f = x*c + g*s; g = -x*s + g*c; h = y*s; y *= c;
  2053. X        if (withV)
  2054. X        {
  2055. X           RectMatrixCol VCI(V,i); RectMatrixCol VCJ(V,i-1);
  2056. X           ComplexScale(VCI, VCJ, c, s);
  2057. X        }
  2058. X        z = sqrt(f*f + h*h); Q.element(i-1) = z; c = f/z; s = h/z;
  2059. X        f = c*g + s*y; x = -s*g + c*y;
  2060. X        if (withU)
  2061. X        {
  2062. X           RectMatrixCol UCI(U,i); RectMatrixCol UCJ(U,i-1);
  2063. X           ComplexScale(UCI, UCJ, c, s);
  2064. X        }
  2065. X     }
  2066. X     E.element(l) = 0.0; E.element(k) = f; Q.element(k) = x;
  2067. X      }
  2068. X      if (l!=k) { Throw(ConvergenceException(A)); }
  2069. X// convergence:
  2070. X      if (z < 0.0)
  2071. X      {
  2072. X     Q.element(k) = -z;
  2073. X     if (withV) { RectMatrixCol VCI(V,k); VCI.Negate(); }
  2074. X      }
  2075. X   }
  2076. X}
  2077. X
  2078. Xvoid SVD(const Matrix& A, DiagonalMatrix& D)
  2079. X{ Matrix U; SVD(A, D, U, U, FALSE, FALSE); }
  2080. X
  2081. X
  2082. END_OF_FILE
  2083. if test 4482 -ne `wc -c <'svd.cxx'`; then
  2084.     echo shar: \"'svd.cxx'\" unpacked with wrong size!
  2085. fi
  2086. # end of 'svd.cxx'
  2087. fi
  2088. echo shar: End of archive 6 \(of 8\).
  2089. cp /dev/null ark6isdone
  2090. MISSING=""
  2091. for I in 1 2 3 4 5 6 7 8 ; do
  2092.     if test ! -f ark${I}isdone ; then
  2093.     MISSING="${MISSING} ${I}"
  2094.     fi
  2095. done
  2096. if test "${MISSING}" = "" ; then
  2097.     echo You have unpacked all 8 archives.
  2098.     rm -f ark[1-9]isdone
  2099. else
  2100.     echo You still need to unpack the following archives:
  2101.     echo "        " ${MISSING}
  2102. fi
  2103. ##  End of shell archive.
  2104. exit 0
  2105.  
  2106. exit 0 # Just in case...
  2107.