GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-May-2007, 04:27
molatelo molatelo is offline
New Member
 
Join Date: Apr 2007
Posts: 3
molatelo is on a distinguished road

c++ matrix operation


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 functions to calculate the dot and cross products as well as calculating the transpose and the inverse of a matrix. And also the methods to traverse the matrix row by row as well as column by column.

Can anyone help me?
CPP / C++ / C Code:
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;
	}
}
Last edited by LuciWiz : 10-May-2007 at 06:08. Reason: Fixed ending code tag
  #2  
Old 10-May-2007, 08:10
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,648
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: c++ matrix operation


Quote:
Originally Posted by molatelo

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

Now I'm trying to do a functions to calculate the dot and cross products as well as calculating the transpose and the inverse of a matrix. And also the methods to traverse the matrix row by row as well as column by column.
For dot, cross, transpose, just use the definitions. All of them are at least as "easy" as matrix multiplication. If you try to apply one of these definitions but get stuck then:

1. Post the code that you tried, including a main() function that tests the operation in question.
2. Post the input that you gave the function for testing
3. Show the output that the program.
4. Tell us what you don't understand about the difference between 2 and 3.

If by "traversing" you mean printing out the values of the elements, then just make two loops:
If you want to print out row by row:
The outer loop index ranges from 0 to the number of rows and the inner loop ranges from 0 to the number of columns. Print out the matrix value for each step of the inner loop.

For the inverse: well, that's a little more involved. One of the more popular and effective methods is called Gauss Jordan. Look it up.


Regards,

Dave
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help... A small problem with allocating memory Cristovao C++ Forum 4 17-Jan-2007 15:17
i need help in C++ PLZ its_me C++ Forum 3 04-Dec-2006 21:51
debugging multi-dimensional vector/ matrix class counterflow C++ Forum 1 15-Mar-2006 12:14
Combining Vectors and References Frankg C++ Forum 7 14-Jan-2006 06:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:01.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.