本文整理汇总了C++中Matrix::Determinant方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::Determinant方法的具体用法?C++ Matrix::Determinant怎么用?C++ Matrix::Determinant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::Determinant方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gaussian
double unsupervised::gaussian(const ColumnVector& ob, const ColumnVector& mix_mu, const Matrix& mix_sigma){
ColumnVector tmp(Dim);
tmp = ob-mix_mu;
double x = (tmp.t() * mix_sigma.i() * tmp).AsScalar();
if(x<0.0) x = 0.0; //for avoiding the failure from calculation error of newmat library.
tmp.CleanUp();
return (exp(x*(-0.5)) / (pow(2.0*M_PI,ob.Nrows()*0.5)*pow(mix_sigma.Determinant(),0.5)));
}
示例2: AdvancedMatrixTests
bool AdvancedMatrixTests()
{
Matrix m(1, 0, 0, 0,
0, 2, 0, 0,
0, 0, 3, 0,
0, 0, 0, 4);
float trace = m.Trace();
float expectedTrace = 1 + 2 + 3 + 4;
if (trace != expectedTrace)
{
wprintf(L"trace didn't match! %f\n", trace);
return false;
}
float det = m.Determinant();
// that's a non-reflective, scaling matrix with a scale > 1, so we should have a pos det > 1
if (det <= 1)
{
wprintf(L"determinant wasn't > 1! %f\n", det);
return false;
}
Matrix invM;
// we only don't have an inverse if det(M) == 0
if (m.Inverse(&invM) != (det != 0))
{
wprintf(L"inverse existence didn't match determinant! %f\n", det);
return false;
}
// if we had an inverse, let's verify it
if (det != 0)
{
// first, m * invM == I
Matrix testForIdentity = m * invM;
// quick test for identiy is trace == 4 && det = 1. Not perfect, but good enough
if (testForIdentity.Trace() != 4 || testForIdentity.Determinant() != 1)
{
wprintf(L"M * invM != I!\n");
return false;
}
// second, inverting the inverse should give us the original matrix
Matrix testM;
if (!invM.Inverse(&testM))
{
return false;
}
if (testM.Trace() != trace || testM.Determinant() != det)
{
wprintf(L"inverting the inverse didn't appear to give the original matrix!\n");
return false;
}
}
// inverse of an orthonormal matrix (any rotation matrix) is equivelant to it's transpose
Matrix m2(Matrix::CreateFromAxisAngle(Vector3(0.707f, 0.707f, 0.0f), 1.234f));
Matrix invM2;
if (!m2.Inverse(&invM2))
{
return false;
}
Matrix transM2 = m2.Transpose();
if (invM2.Trace() != transM2.Trace() || invM2.Determinant() != transM2.Determinant())
{
return false;
}
// another inverse test
Matrix m3(1, 2, 0, 0,
4, 0, 4, 0,
0, 8, 8, 0,
1, 0, 2, 1);
Matrix invM3;
if (!m3.Inverse(&invM3))
{
return false;
}
DirectX::XMMATRIX xm = m3;
DirectX::XMVECTOR xdet;
DirectX::XMMATRIX invXM = DirectX::XMMatrixInverse(&xdet, xm);
DirectX::XMFLOAT4X4 invXMF;
DirectX::XMStoreFloat4x4(&invXMF, invXM);
return true;
}
示例3:
TEST(MatrixTests, Determinant)
{
Matrix test = Matrix::RotationX(1.0f) * Matrix::Translation(1.0f, 2.0f, 3.0f);
ASSERT_FLOAT_EQ(D3DXMatrixDeterminant(reinterpret_cast<D3DXMATRIX*>(&test)), test.Determinant());
}