-
Matrix multiplication!!
I have created a class of 3*3 matrix. In which i have defined an operator for matrix multiplication.
the code goes like this:
Code:
matrix operator * (matrix m)
{
matrix x;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
x.array[i][j]=array[1][j] * m.array[i][1];
x.array[i][j]=array[2][j] * m.array[i][2];
x.array[i][j]=array[3][j] * m.array[i][3];
return x;
}
can anybuddy help me this code is wrong
-
Easy start: If you intend all of those statements to be inside a loop, you will need braces.
You seem to have looked up matrix multiplication, but you forgot about the additions.
-
Here's a hint:
result[i][j] += array [i][k] * array[k][j]
-
Here's another important hint: Arrays start at zero. An array with three elements has valid indexes [0], [1], and [2]. You got the loops right, bt not your hard-coded indexes.
-
Check your curly brackets, your code isn't doing what you think it is doing.
You need to put brackets after the second for statement