Exemple #1
0
//==========================================================================
// Class:			Matrix
// Function:		GetPsuedoInverse
//
// Description:		Returns the pseudo-inverse of this matrix.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		inverse	= Matrix&, inverse of this
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool Matrix::GetPsuedoInverse(Matrix &inverse) const
{
	// Use singular value decomposition to compute the inverse
	// SVD algorithm interpreted from Numerical Recipies in C
	Matrix U;
	Matrix W;
	Matrix V;

	if (!GetSingularValueDecomposition(U, V, W))
		return false;

	inverse = V * W.GetDiagonalInverse() * U.GetTranspose();
	return true;
}
Exemple #2
0
//==========================================================================
// Class:			Matrix
// Function:		LeftDivide
//
// Description:		Performs division from the left.  For example, to solve
//					Ax=b for x, left divide x = A \ b, where this matrix is A.
//					Same as A^-1 * b.
//
// Input Arguments:
//		b	= const Matrix& vector to divide this into
//
// Output Arguments:
//		x	= Matrix&
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool Matrix::LeftDivide(const Matrix &b, Matrix &x) const
{
	// Normal equations solution (not very robust?)
	//return GetInverse() * b;

	// Use singular value decomposition
	Matrix U;
	Matrix V;
	Matrix W;

	if (!GetSingularValueDecomposition(U, V, W))
		return false;

	x = V * W.GetDiagonalInverse().GetTranspose() * U.GetTranspose() * b;
	return true;
}