2 Replies - 2468 Views - Last Post: 15 January 2010 - 11:59 AM Rate Topic: -----

#1 ohs14  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 13-October 09

I have a question about 3x3 Matrix(class)

Posted 14 January 2010 - 09:27 PM

/////////////////////
#include<iostream>
using namespace std;

class matrices
{
 public:
  void myreadin();
  void addmatrices();  /////// addition
  void submatrices();  /////// subtraction
  void multimatrices(); /////// multiplication
  void invermatrices(); ////// inverse
 // void determatrices(); //////determinant
 private:
  float a[3][3]; ///// a matrix
  float b[3][3]; //// another matrix
  float c[3][3]; ///// result thru c
};
int main()
{
  matrices m1;
  printf("Please enter each elements about matrix \n");
  m1.myreadin();
  m1.addmatrices();
  m1.submatrices();
  m1.multimatrices();
  m1.invermatrices();
//  m1.determatrices();
  return 0;
}
void matrices::myreadin()
{
  for (int i=0; i<3; i++)
	scanf("%f %f ",&a[i],&b[i]);
}
void matrices::addmatrices()
{
  int i,o;
  for (int i=0; i<3; i++)
  {
	for (int o=0; o<3; o++)
	{
	  c[i][o]=a[i][o]+b[i][o];
	  printf("%d ",c[i][o]);
	}
	printf("\n");
  }
}
void matrices::submatrices()
{
  int i,o;
  for (int i=0; i<3; i++)
	{
	  for (int o=0; o<3; o++)
		{
		  c[i][o]=a[i][o]-b[i][o];
 printf("%d ",c[i][o]);
		}
	  printf("\n");
	}
}
void matrices::multimatrices()
{
  int q,w,e;
  for(int q=0; q<3; q++)
	for(int w=0; w<3; w++)
	  {
		c[w][e]+ = a[w][q] * b[q][e]; ///////////// If i compile, this part is weird.
	  }
}
void matrices::invermatrices()
{
  int i,j;
  for(int i=0; i<3; i++)
	{
	  printf("%d please enter \n",i+1);
	  for(int j=0; j<3; j++)
		{
		  printf("%d please enter \n",j+1);
		  scanf("%f", &a[i][j]);
		}
		  printf("\n");
	 }
}

//void matrices::determatrices()

.

/////////////////////////////////



I need to write a C++ program to do matrix operations. Addition, subtraction,multiplication, inverse of a matrix, and find the determinant of a matrix.... I did roughly addition, subtraction, and muliplcation parts, but not inverse of a matrix, and determinant part..... Can you guys please help me? And I also need to print out but, I am not sure how to do it ...

Is This A Good Question/Topic? 1
  • +

Replies To: I have a question about 3x3 Matrix(class)

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: I have a question about 3x3 Matrix(class)

Posted 14 January 2010 - 10:33 PM

...
void matrices::multimatrices()
{
  int q,w,e;<<<<<<<<<<Variable "e" is not initialized.

  for(int q=0; q<3; q++)
	for(int w=0; w<3; w++)
	  {
///		c[w][e]+ = a[w][q] * b[q][e]; ///////////// If i compile, this part is weird.
		c[w][e] += (a[w][q] * b[q][e]); ///////////// I like explicit parens :)
	  }
}
...


Was This Post Helpful? 0
  • +
  • -

#3 ohs14  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 13-October 09

Re: I have a question about 3x3 Matrix(class)

Posted 15 January 2010 - 11:59 AM

void matrices::multimatrices()
{
  int q,w,e;

  for(int q=0; q<3; q++)
	for(int w=0; w<3; w++)
					 for(int e=0; e<3; e++)
	  {
	
		c[w][e] += (a[w][q] * b[q][e]); 
							  printf("%d ",c[w][e]);
				  }
			  printf("\n");

	  
}



even if I type the code like this, it still doesn't compile....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1