⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newmat2.cpp

📁 各种矩阵算法库。支持UpperTriangularMatrix,LowerTriangularMatrix, DiagonalMatrix, SymmetricMatrix, BandMatrix,U
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//$$ newmat2.cpp      Matrix row and column operations// Copyright (C) 1991,2,3,4: R B Davies#define WANT_MATH#include "include.h"#include "newmat.h"#include "newmatrc.h"#ifdef use_namespacenamespace NEWMAT {#endif#ifdef DO_REPORT#define REPORT { static ExeCounter ExeCount(__LINE__,2); ++ExeCount; }#else#define REPORT {}#endif//#define MONITOR(what,storage,store) { cout << what << " " << storage << " at " << (long)store << "\n"; }#define MONITOR(what,store,storage) {}/************************** Matrix Row/Col functions ************************/void MatrixRowCol::Add(const MatrixRowCol& mrc){   // THIS += mrc   REPORT   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;   if (f < skip) f = skip; if (l > lx) l = lx; l -= f;   if (l<=0) return;   Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);   while (l--) *elx++ += *el++;}void MatrixRowCol::AddScaled(const MatrixRowCol& mrc, Real x){   REPORT   // THIS += (mrc * x)   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;   if (f < skip) f = skip; if (l > lx) l = lx; l -= f;   if (l<=0) return;   Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);   while (l--) *elx++ += *el++ * x;}void MatrixRowCol::Sub(const MatrixRowCol& mrc){   REPORT   // THIS -= mrc   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;   if (f < skip) f = skip; if (l > lx) l = lx; l -= f;   if (l<=0) return;   Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);   while (l--) *elx++ -= *el++;}void MatrixRowCol::Inject(const MatrixRowCol& mrc)// copy stored elements only{   REPORT   int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;   if (f < skip) f = skip; if (l > lx) l = lx; l -= f;   if (l<=0) return;   Real* elx=data+(f-skip); Real* ely=mrc.data+(f-mrc.skip);   while (l--) *elx++ = *ely++;}Real DotProd(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2){   REPORT                                         // not accessed   int f = mrc1.skip; int f2 = mrc2.skip;   int l = f + mrc1.storage; int l2 = f2 + mrc2.storage;   if (f < f2) f = f2; if (l > l2) l = l2; l -= f;   if (l<=0) return 0.0;   Real* el1=mrc1.data+(f-mrc1.skip); Real* el2=mrc2.data+(f-mrc2.skip);   Real sum = 0.0;   while (l--) sum += *el1++ * *el2++;   return sum;}void MatrixRowCol::Add(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2){   // THIS = mrc1 + mrc2   int f = skip; int l = skip + storage;   int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;   if (f1<f) f1=f; if (l1>l) l1=l;   int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;   if (f2<f) f2=f; if (l2>l) l2=l;   Real* el = data + (f-skip);   Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip);   if (f1<f2)   {      int i = f1-f; while (i--) *el++ = 0.0;      if (l1<=f2)                              // disjoint      {	 REPORT                                // not accessed         i = l1-f1;     while (i--) *el++ = *el1++;         i = f2-l1;     while (i--) *el++ = 0.0;         i = l2-f2;     while (i--) *el++ = *el2++;         i = l-l2;      while (i--) *el++ = 0.0;      }      else      {         i = f2-f1;    while (i--) *el++ = *el1++;         if (l1<=l2)         {            REPORT            i = l1-f2; while (i--) *el++ = *el1++ + *el2++;            i = l2-l1; while (i--) *el++ = *el2++;            i = l-l2;  while (i--) *el++ = 0.0;         }         else         {            REPORT            i = l2-f2; while (i--) *el++ = *el1++ + *el2++;            i = l1-l2; while (i--) *el++ = *el1++;            i = l-l1;  while (i--) *el++ = 0.0;         }      }   }   else   {      int i = f2-f; while (i--) *el++ = 0.0;      if (l2<=f1)                              // disjoint      {	 REPORT                                // not accessed         i = l2-f2;     while (i--) *el++ = *el2++;         i = f1-l2;     while (i--) *el++ = 0.0;	 i = l1-f1;     while (i--) *el++ = *el1++;	 i = l-l1;      while (i--) *el++ = 0.0;      }      else      {         i = f1-f2;    while (i--) *el++ = *el2++;         if (l2<=l1)         {	    REPORT            i = l2-f1; while (i--) *el++ = *el1++ + *el2++;            i = l1-l2; while (i--) *el++ = *el1++;            i = l-l1;  while (i--) *el++ = 0.0;         }         else         {	    REPORT            i = l1-f1; while (i--) *el++ = *el1++ + *el2++;            i = l2-l1; while (i--) *el++ = *el2++;            i = l-l2;  while (i--) *el++ = 0.0;         }      }   }}void MatrixRowCol::Sub(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2){   // THIS = mrc1 - mrc2   int f = skip; int l = skip + storage;   int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;   if (f1<f) f1=f; if (l1>l) l1=l;   int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;   if (f2<f) f2=f; if (l2>l) l2=l;   Real* el = data + (f-skip);   Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip);   if (f1<f2)   {      int i = f1-f; while (i--) *el++ = 0.0;      if (l1<=f2)                              // disjoint      {	 REPORT                                // not accessed         i = l1-f1;     while (i--) *el++ = *el1++;         i = f2-l1;     while (i--) *el++ = 0.0;         i = l2-f2;     while (i--) *el++ = - *el2++;         i = l-l2;      while (i--) *el++ = 0.0;      }      else      {         i = f2-f1;    while (i--) *el++ = *el1++;         if (l1<=l2)         {	    REPORT            i = l1-f2; while (i--) *el++ = *el1++ - *el2++;            i = l2-l1; while (i--) *el++ = - *el2++;            i = l-l2;  while (i--) *el++ = 0.0;         }         else         {	    REPORT            i = l2-f2; while (i--) *el++ = *el1++ - *el2++;            i = l1-l2; while (i--) *el++ = *el1++;            i = l-l1;  while (i--) *el++ = 0.0;         }      }   }   else   {      int i = f2-f; while (i--) *el++ = 0.0;      if (l2<=f1)                              // disjoint      {	 REPORT                                // not accessed         i = l2-f2;     while (i--) *el++ = - *el2++;         i = f1-l2;     while (i--) *el++ = 0.0;         i = l1-f1;     while (i--) *el++ = *el1++;         i = l-l1;      while (i--) *el++ = 0.0;      }      else      {         i = f1-f2;    while (i--) *el++ = - *el2++;         if (l2<=l1)         {	    REPORT            i = l2-f1; while (i--) *el++ = *el1++ - *el2++;            i = l1-l2; while (i--) *el++ = *el1++;            i = l-l1;  while (i--) *el++ = 0.0;         }         else         {            REPORT            i = l1-f1; while (i--) *el++ = *el1++ - *el2++;            i = l2-l1; while (i--) *el++ = - *el2++;            i = l-l2;  while (i--) *el++ = 0.0;         }      }   }}void MatrixRowCol::Add(const MatrixRowCol& mrc1, Real x){   // THIS = mrc1 + x   REPORT   if (!storage) return;   int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;   if (f < skip) { f = skip; if (l < f) l = f; }   if (l > lx) { l = lx; if (f > lx) f = lx; }   Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);   int l1 = f-skip;  while (l1--) *elx++ = x;       l1 = l-f;     while (l1--) *elx++ = *ely++ + x;       lx -= l;      while (lx--) *elx++ = x;}void MatrixRowCol::NegAdd(const MatrixRowCol& mrc1, Real x){   // THIS = x - mrc1   REPORT   if (!storage) return;   int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;   if (f < skip) { f = skip; if (l < f) l = f; }   if (l > lx) { l = lx; if (f > lx) f = lx; }   Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);   int l1 = f-skip;  while (l1--) *elx++ = x;       l1 = l-f;     while (l1--) *elx++ = x - *ely++;       lx -= l;      while (lx--) *elx++ = x;}void MatrixRowCol::RevSub(const MatrixRowCol& mrc1){   // THIS = mrc - THIS   REPORT   if (!storage) return;   int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;   if (f < skip) { f = skip; if (l < f) l = f; }   if (l > lx) { l = lx; if (f > lx) f = lx; }   Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -