当前位置: 首页>>代码示例>>C++>>正文


C++ MatrixTemplate类代码示例

本文整理汇总了C++中MatrixTemplate的典型用法代码示例。如果您正苦于以下问题:C++ MatrixTemplate类的具体用法?C++ MatrixTemplate怎么用?C++ MatrixTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MatrixTemplate类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LBackSubstitute

inline bool LBackSubstitute(const MatrixTemplate<T>& a, const MatrixTemplate<T>& b, MatrixTemplate<T>& x)
{
  if(x.isEmpty()) x.resize(a.n,b.n);
  else Assert(x.m == a.n && x.n == b.n);
  for(int i=0;i<x.n;i++) {
    VectorTemplate<T> xi,bi;
    x.getColRef(i,xi);
    b.getColRef(i,bi);
    if(!LBackSubstitute(a,bi,xi)) return false;
  }
  return true;
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:12,代码来源:backsubstitute.cpp

示例2: Lt1BackSubstitute

inline void Lt1BackSubstitute(const MatrixTemplate<T>& a, const MatrixTemplate<T>& b, MatrixTemplate<T>& x)
{
  if(x.isEmpty()) 
    x.resize(a.n,b.n);
  else Assert(x.m == a.n && x.n == b.n);
  for(int i=0;i<x.n;i++) {
    VectorTemplate<T> xi,bi;
    x.getColRef(i,xi);
    b.getColRef(i,bi);
    Lt1BackSubstitute(a,bi,xi);
  }
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:12,代码来源:backsubstitute.cpp

示例3: LtBackSubstitute

bool LtBackSubstitute(const MatrixTemplate<T>& a, const VectorTemplate<T>& b, VectorTemplate<T>& x)
{ 
  Assert(a.isSquare());
  Assert(a.n == b.n);
  if(x.empty()) x.resize(a.n);
  else Assert(a.n == x.n);
  int n=a.n;
 	T aii,sum;
	for(int i=n-1; i>=0; i--) {
		aii=a(i,i);
		sum=b[i];
		for(int j=i+1; j<n; j++)
			sum-=a(j,i)*x[j];
		if(aii == 0) {
		  if(!FuzzyZero(sum,(T)kBackSubZeroTolerance)) {
		    //LOG4CXX_ERROR(KrisLibrary::logger(),"LtBackSubstitute: dividing by zero: "<<sum<<"/"<<aii);
		    return false;
		  }
		  x[i]=0;
		}
		else
		  x[i]=sum/aii;
	}
	return true;
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:25,代码来源:backsubstitute.cpp

示例4: ReduceRowEchelon

void ReduceRowEchelon(MatrixTemplate<T>& A,MatrixTemplate<T>& B)
{
  if(!B.isEmpty())
    Assert(B.m == A.m);

  int i,j,icur,jcur;
  for(icur=A.m-1;icur>=0;icur--) { 
    //find pivot for row icur
    jcur = -1;
    for(j=0;j<A.n;j++) if(A(icur,j) != 0) { jcur=j; break; }
    if(jcur == -1) continue;

    //normalize row by dividing by A(icur,jcur)
    T scale = One/A(icur,jcur);
    A(icur,jcur) = 1;
    for(j=jcur+1;j<A.n;j++) A(icur,j) *= scale;
    for(j=0;j<B.n;j++) B(icur,j) *= scale;

    //zero out columns above (icur,jcur)
    for(i=0;i<icur;i++) {
      if(A(i,jcur) == 0) continue;
      scale = A(i,jcur);
      A(i,jcur) = 0;
      for(j=jcur+1;j<A.n;j++) A(i,j) -= A(icur,j)*scale;
      for(j=0;j<B.n;j++) B(i,j) -= B(icur,j)*scale;
    }
  }
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:28,代码来源:RowEchelon.cpp

示例5: LBackSubstitute

bool LBackSubstitute(const MatrixTemplate<T>& a, const VectorTemplate<T>& b, VectorTemplate<T>& x)
{
  Assert(a.isSquare());
  Assert(a.n == b.n);
  if(x.empty()) x.resize(a.n);
  else Assert(a.n == x.n);
  int n=a.n;
	T aii,sum;
	for(int i=0; i<n; i++) {
		aii=a(i,i);
		sum=b[i];
		for(int j=0; j<i; j++)
			sum-=a(i,j)*x[j];
		if(aii == 0) {
		  if(!FuzzyZero(sum,(T)kBackSubZeroTolerance)) {
		    //cerr<<"LBackSubstitute: dividing by zero: "<<sum<<"/"<<aii<<endl;
		    //cerr<<MatrixPrinter(a)<<endl;
		    return false;
		  }
		  x[i]=0;
		}
		else
		  x[i]=sum/aii;
	}
	return true;
}
开发者ID:panjia1983,项目名称:mintos,代码行数:26,代码来源:backsubstitute.cpp

示例6: CHECKRESIZE

void MatrixTemplate<T>::copy(const MatrixTemplate<T2>& a)
{
  CHECKRESIZE(a.m,a.n);
  MatrixIterator<T> k=begin();
  MatrixIterator<T2> ak=a.begin();
  for(int i=0;i<m;i++,k.nextRow(),ak.nextRow())
    for(int j=0;j<n;j++,k.nextCol(),ak.nextCol())
      *k = (T)*ak;
}
开发者ID:panjia1983,项目名称:mintos,代码行数:9,代码来源:MatrixTemplate.cpp

示例7: U1BackSubstitute

void U1BackSubstitute(const MatrixTemplate<T>& a, const VectorTemplate<T>& b, VectorTemplate<T>& x)
{ 
  Assert(a.isSquare());
  Assert(a.n == b.n);
  if(x.empty()) x.resize(a.n);
  else Assert(a.n == x.n);
  int n=a.n;
  T sum;
	for(int i=n-1; i>=0; i--) {
		sum=b(i);
		for(int j=i+1; j<n; j++)
			sum-=a(i,j)*x[j];
    x[i]=sum;
	}
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:15,代码来源:backsubstitute.cpp

示例8: L1BackSubstitute

void L1BackSubstitute(const MatrixTemplate<T>& a, const VectorTemplate<T>& b, VectorTemplate<T>& x)
{
  Assert(a.isSquare());
  Assert(a.n == b.n);
  if(x.empty()) x.resize(a.n);
  else Assert(a.n == x.n);
  int n=a.n;
	T sum;
	for(int i=0; i<n; i++) {
		sum=b[i];
		for(int j=0; j<i; j++)
			sum-=a(i,j)*x[j];
		x[i]=sum;
	}
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:15,代码来源:backsubstitute.cpp

示例9: RowEchelonDecompose

int RowEchelonDecompose(MatrixTemplate<T>& A,MatrixTemplate<T>& B,Real zeroTol)
{
  if(!B.isEmpty())
    Assert(B.m == A.m);
  int m=A.m,n=A.n;
  int p=B.n;

  int i,j,icur=0,jcur;
  T temp;
  for(jcur=0;jcur<n;jcur++) {
    //find pivot element in col jcur from rows icur..m
    Real big=Zero;
    int ipivot=-1;
    for(i=icur;i<m;i++) {
      if(Abs(A(i,jcur)) > big) {
	ipivot = i;
	big = Abs(A(i,jcur));
      }
    }
    if(!FuzzyZero(big,zeroTol)) { //nonzero pivot found
      //exchange rows ipivot,icur
      if(ipivot != icur) {
	for(j=jcur;j<n;j++) SWAP(A(ipivot,j),A(icur,j));
	for(j=0;j<p;j++) SWAP(B(ipivot,j),B(icur,j));
      }
      //eliminate rows below icur
      T scale;
      for(i=icur+1;i<m;i++) {
	//set row(ai) = row(ai)-aiJ/aIJ*row(aI)
	scale = A(i,jcur)/A(icur,jcur);
	for(j=jcur;j<n;j++) A(i,j) -= A(icur,j)*scale;
	for(j=0;j<p;j++) B(i,j) -= B(icur,j)*scale;
	A(i,jcur)=Zero;
      }
      icur++;
    }
    else {
      //either zero pivot, or very small one
      //set to zero to reduce numerical difficulties later 
      for(i=icur;i<m;i++) A(i,jcur)=Zero;
    }
  }
  return Max(m-icur,n-jcur);
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:44,代码来源:RowEchelon.cpp


注:本文中的MatrixTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。