# I have a question about 3x3 Matrix(class)

Page 1 of 1

## 2 Replies - 3047 Views - Last Post: 15 January 2010 - 11:59 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=150008&amp;s=075d8a7cf2d8a0572e8eaee2a440b3b4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ohs14

Reputation: 2
• 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 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;
m1.submatrices();
m1.multimatrices();
m1.invermatrices();
//  m1.determatrices();
return 0;
}
{
for (int i=0; i<3; i++)
scanf("%f %f ",&a[i],&b[i]);
}
{
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++)
{
for(int j=0; j<3; j++)
{
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

• --... ...-- -.. . -. ---.. .-- -..- ...

Reputation: 972
• 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 :)
}
}
...

### #3 ohs14

Reputation: 2
• 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....