Hi!

I'm building a Class for matrixes.

I have already built several funtions for adding, subtracting, transpose, multiply,..

Now I'm trying to do a function to calculate the inverse...

Can anyone help me?

class CMatrix  
{
public:
	void Identity();
	void SetMaxColRow(int nRow, int nCol);
	void SetElement(int nRow, int nCol, double element);
	void Show();

	double GetElement(int nRow, int nCol);

	CMatrix operator+(CMatrix tmpMatriz);
	CMatrix operator-(CMatrix tmpMatriz);
	CMatrix operator*(double scalar);
	CMatrix operator*(CMatrix tmpMatriz);
	CMatrix Transpose();
	CMatrix(int nRows, int nCols);
	CMatrix();
	
	virtual ~CMatrix();
	
	int m_nRows;
	int m_nCols;
	

private:
	double **m_pMatriz;





// constructor
CMatrix::CMatrix(int nRows, int nCols)
{
	m_nCols= nCols;
	m_nRows = nRows;

	m_pMatriz = new double* [m_nRows];
	for (int i=0; i<m_nRows; i++)
	{
		m_pMatriz[i] = new double[m_nCols];
		for (int j=0; j<m_nCols; j++)
			m_pMatriz[i][j] = 1.0;
	}
}

According to this source, if your scroll down to the bottom, the inverse of a square matrix can be found with an application of Gaussian elimination.

http://lagrange.la.asu.edu/VirtualClass/Algebra/1stCourseLinAlg/node3.html


And here is an actual implementation for Gaussian elimination written in c++. It shouldn't be too hard to merge the two to get a proceedure for finding the inverse. I like it better than having to work out the matrix of cofactors anywhoo.

http://www.daniweb.com/techtalkforums/thread41803.html

The only caveat I can see is that using Gaussian elimination to find an inverse is somewhat counter-productive.

In most real life circumstances you would be using the inverse to solve for a system of simultaneous equations. Since Gaussian elimination does this anyway it is kind of pointless to be using it to ascertain the inverse.

i dont know if this helps but allways rember that there is always an equil and opposite reaction so to create the inverce write the code in the inverse way but keep the structure the same

Comments
The most useless thing I've ever read.

According to this source, if your scroll down to the bottom, the inverse of a square matrix can be found with an application of Gaussian elimination.

http://lagrange.la.asu.edu/VirtualClass/Algebra/1stCourseLinAlg/node3.html

I couldn't see waht's in this page... I've tried with firefox and ie but couldn't see either...

And here is an actual implementation for Gaussian elimination written in c++. It shouldn't be too hard to merge the two to get a proceedure for finding the inverse. I like it better than having to work out the matrix of cofactors anywhoo.

http://www.daniweb.com/techtalkforums/thread41803.html

The only caveat I can see is that using Gaussian elimination to find an inverse is somewhat counter-productive.

In most real life circumstances you would be using the inverse to solve for a system of simultaneous equations. Since Gaussian elimination does this anyway it is kind of pointless to be using it to ascertain the inverse.

I didn't quite understand how to use Gaussian elimination in order to obtain the inverse... :o


thanks

>I couldn't see waht's in this page... I've tried with firefox and ie but couldn't see either...

Hmm, that's odd. Try this link all should be clear.

http://www.glue.umd.edu/~NSW/ench250/gauss.htm

>I didn't quite understand how to use Gaussian elimination in order to obtain the inverse...

google +matrix inverse Gaussian elimination

Should quickly remedy that.

[note to dani] I've tried latexing up some matrices but had no luck displaying them properly[/note]

This article has been dead for over six months. Start a new discussion instead.