本文整理汇总了C++中Matrix::EyeMat方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::EyeMat方法的具体用法?C++ Matrix::EyeMat怎么用?C++ Matrix::EyeMat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::EyeMat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tst_lupdecompose
void tst_lupdecompose(void)
{
double EPS=1e-10;
Matrix ww;
ww.EyeMat(3);
ww(1,0)=10;//make it not diagnal dominate.
Matrix ll,uu,pp;
ww.LUPdecompose(ll,uu,pp);
Matrix r0,r1,r2;
MatrixMultiply(ll,uu,r0);
MatrixMultiply(pp,ww,r1);
MatrixSub(r0,r1,r2);
assert(r2.fnorm()<EPS);
ww.EyeMat(20);
for(int i=0;i<20*20;i++){
ww.data[i]=(rand() % 100 - 50) /100.0;//make it not diagnal dominate.
}
ww.LUPdecompose(ll,uu,pp);
MatrixMultiply(ll,uu,r0);
MatrixMultiply(pp,ww,r1);
MatrixSub(r0,r1,r2);
assert(r2.fnorm()<EPS);
try{
Matrix a(3,4);
a.LUPdecompose(ll,uu,pp);
}
catch(MatrixException e){
assert(e.matrixExceptionType==DIM_NOT_MATCH);
}
}
示例2: tst_getinversion
void tst_getinversion(void)
{
double EPS=1e-10;
srand ( 60637);
Matrix mm(20,20);
for(int i=0; i<20*20; i++)mm(i/20,i%20)=(rand() % 10000)/10000.0;
Matrix invmm;
mm.GetInversion(invmm);
Matrix i20;
i20.EyeMat(20);
Matrix r0,r1;
MatrixMultiply(invmm,mm,r0);
MatrixSub(r0,i20,r1);
assert(r1.fnorm()<EPS);
const int n = 20;
Matrix m(n,n);
for (int i=0; i < n; i++) m(i,i) = 0.01;
Matrix inverse;
m.GetInversion(inverse);
for (int i=0; i < n; i++) assert(fabs(inverse(i,i)-100)<EPS);
try{
Matrix a(3,3);
for(int i=0;i<2;i++)
a.data[i*3+i]=i;
//a is not full rank;
Matrix b;
a.GetInversion(b);
}
catch(MatrixException e){
assert(e.matrixExceptionType==NOT_FULL_RANK);
}
try{
Matrix a(3,4);
for(int i=0;i<3;i++)
a.data[i*4+i]=1;
Matrix b;
a.GetInversion(b);
}
catch(MatrixException e){
assert(e.matrixExceptionType==DIM_NOT_MATCH);
}
for(int hh=0;hh<10000;hh++){
try{
int dim=rand() % 100;
Matrix mm(dim,dim);
for(int i=0;i<dim*dim;i++)
mm.data[i]=((rand() -50) % 100)/100.0;
Matrix imm;
mm.GetInversion(imm);
Matrix ll,uu,pp;
imm.LUPdecompose(ll,uu,pp);
double condmax=0;
double condmin=1e20;
for(int i=0;i<dim;i++){
if(fabs(uu.data[i*dim+i])<condmin)
condmin=fabs(uu.data[i*dim+i]);
if(fabs(uu.data[i*dim+i])>condmax)
condmax=fabs(uu.data[i*dim+i]);
}
double cond=condmax/condmin;
Matrix immmm;
MatrixMultiply(imm,mm,immmm);
Matrix eyedim;
eyedim.EyeMat(dim);
immmm.subtract(eyedim);
assert(immmm.fnorm()<1e-5);
}
catch(MatrixException e){
string s=e.what();
}
}
}