WAKS wrote: |
---|
I have created my program so every matrix counts from 1-SIZE. Becuase it's easier for me to think on the math when everything counts from 1. I have therefore changed every for loop to go from 1 to <= SIZE instead of 0 to < SIZE. |
I hope you have also allocated the extra space when creating the matrix.
|
double board[SIZE + 1][SIZE + 1];
|
WAKS wrote: |
---|
That could be the problem, but how could I fix that? |
I was going to suggest you should use another matrix to store the result but I see you are already using two different matrices. I think you should read both values that you multiply from the board array (at the moment you read one from board and one from result).
|
result[i][n] += board[i][k] * board[k][n];
|
Now if you initialize the result array to zero, and the while loop only runs once (meaning you only want to multiply the matrix with itself once) you will probably get the correct result.
To be able to handle multiple matrix multiplications you would have to make sure that the values of result is copied (or in some other way transferred) to board after each matrix multiplication. You also need to make sure the result array is restored to zero before each matrix multiplication.
To make the code easier to work with you might want to separate the code into functions. First you could create a function that do the matrix multiplication (once). When you have tested and made sure that the function is working correctly you can just call it, from your other code, the number of times you want to multiply.
I don't really understand your while loop condition to be honest. Maybe that's how you want it, but just so that you know, if you are using floating point numbers you should be very careful comparing them using == because floating point values are not always exact and might contain rounding errors.