本文整理汇总了C++中Matrix::Det方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::Det方法的具体用法?C++ Matrix::Det怎么用?C++ Matrix::Det使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::Det方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestDet
//
//测试行列式是否计算正确;
void Matrix::TestDet()
{
int test_sum=0;
//
/*/输入;
char * ssb = " \
4 \
1 1 \
5 \
4 4 \
1 1 1 1 \
1 2 4 8 \
1 3 9 27 \
1 4 16 64 \
3 3 \
2 0 1 \
1 -4 -1 \
-1 8 3 \
4 4 \
4 1 2 4 \
1 2 0 2 \
10 5 2 0 \
0 1 1 7 \
";
strstream sst(ssb,strlen(ssb));
cin = sst;//*/
//答案;
double ans[] = {5,12,-4,0};
//
cin >> test_sum;
for(int count=0;count<test_sum;count++)
{
int n,m;
cin >> n >> m;
//
Matrix mat;
mat.NewMatrix(n,m);
mat.ReadStd();
int swp = mat.RowSimplify();
//
if(Equal(mat.Det(swp),ans[count]))
cout << count << ".DetRight" << endl;
else
cout << count << ".DetWrong" << endl;
//
mat.DeleteMatrix();
}
cout << endl;
}
示例2: Det
T Det(){
T res(0);
if (n == 2){
res.SetVal(res.sub(res.mul((mx[0])[0], (mx[1])[1]), res.mul((mx[1])[0], (mx[0])[1])));
return res;
}
for (int j = 0; j < m; j++){
Matrix<T> sm = GetTruncated(0, j);
T a = sm.Det();
a.SetVal(a.mul(a, (mx[0])[j]));
a.SetVal(a.mul(a, a.up(j)));
res.SetVal(res.add(res, a));
}
return res;
}
示例3: CalculateAffineParameters
//.........这里部分代码省略.........
{
MessageBox(NULL,
"Failed to calculate the affine parameters.\nThe application failed to locate eight matching points.",
"Notification",
MB_ICONINFORMATION|MB_OK);
return false;
}
// Matrix y is constructed from the fiducial data.
if (NULL == m_pCalibrationDlg)
{
m_pCalibrationDlg = new CCalibrationDlg;
// Set flag if it is created for this purpose.
bCreateDlgLocal = true;
}
// If failed to optain the calibration data, exit.
if (false == m_pCalibrationDlg->ReadCalibrationData())
{
MessageBox(NULL,
"Failed to calculate the affine parameters.\nThe application failed to obtain the calibration data.",
"Notification",
MB_ICONINFORMATION|MB_OK);
return false;
}
for (iter = m_mapMatchingPoints.begin(); iter != m_mapMatchingPoints.end(); iter++)
{
// Get the value of the matched point.
pID = (*iter).first;
point = (*iter).second;
// Assign the value to the matrix.
// [ xm ym 0 0 1 0; <-- row (pID-1)*2
// 0 0 xm ym 0 1] <-- row (pID-1)*2 + 1
// Set the value for the first row of each point
A.Set( (pID-1)*2, 0, point.fX);
A.Set( (pID-1)*2, 1, point.fY);
A.Set( (pID-1)*2, 2, 0);
A.Set( (pID-1)*2, 3, 0);
A.Set( (pID-1)*2, 4, 1);
A.Set( (pID-1)*2, 5, 0);
// Set the value for the second row of each point
A.Set( (pID-1)*2 +1, 0, 0);
A.Set( (pID-1)*2 +1, 1, 0);
A.Set( (pID-1)*2 +1, 2, point.fX);
A.Set( (pID-1)*2 +1, 3, point.fY);
A.Set( (pID-1)*2 +1, 4, 0);
A.Set( (pID-1)*2 +1, 5, 1);
// Assign the value to the matrix y.
// [ xf; <-- row (pID-1)*2
// yf ] <-- row (pID-1)*2 + 1
y.Set( (pID-1)*2, 0, m_pCalibrationDlg->m_FC[(pID-1)].fX);
y.Set( (pID-1)*2 +1, 0, m_pCalibrationDlg->m_FC[(pID-1)].fY);
}
// Calculate the results as "X = inv(AT A) (AT y)"
Matrix N = A.Trans() * A;
// Check if N inverse exist.
double det = N.Det();
if(det == 0.0 || det <= 1e-10)
{
MessageBox(NULL,
"Failed to calculate the affine parameters.\nThe coordinates are not in a good condition.",
"Notification",
MB_ICONINFORMATION|MB_OK);
return false;
}
// Find the X matrix.
X = N.Inv() * A.Trans() * y;
// Then obtain the affine transformation parameters.
m_a11 = X.Get(0, 0);
m_a12 = X.Get(1, 0);
m_a21 = X.Get(2, 0);
m_a22 = X.Get(3, 0);
m_xt = X.Get(4, 0);
m_yt = X.Get(5, 0);
// Delete the object since it is no longer used.
if (true == bCreateDlgLocal)
{
delete m_pCalibrationDlg;
m_pCalibrationDlg = NULL;
}
m_bCalculatedAffine = true;
return true;
}