I have a Matrix class and I am trying to overload the multiplication sign.
It compiles without error and runs, however it does not display the matrix like it should. So I want to make sure the error is not in my overload operation.
public static Matrix operator *(Matrix lhs, Matrix rhs)
{
Matrix temp = new Matrix();
temp.matrix = new double[rhs.getRow(), rhs.getCol()];
for (int i = 0; i < lhs.getRow(); i++)
{
for (int j = 0; j < lhs.getCol(); j++)
{
temp.matrix[i,0] += lhs.matrix[i,j] * rhs.matrix[j,0];
}
}
return temp;
}
This is my display function, so you can get an idea of what's going on
public string displayMatrix()
{
string display = "";
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
display += String.Format("{0,-15:00.00}", matrix[i, j]);
}
display += "\r\n";
}
return display;
}
This is the code for the form to display it in the textbox
Matrix matrix_b = new Matrix();
matrix_b = matrix_A * matrix_s;
matrixBDisplay.Text = matrix_b.displayMatrix();
Thanks for any help :)
-Miss Vavazoom