C++/matrix multiplication coding
Expert: Joydeep Bhattacharya - 8/1/2007
QuestionHello, Hope you're doing well. I am trying to write a loop program which multiplies inverse of a matrix M1 by matrix M2 twenty times iterating their variable i from 1 to 20. Each matrix M1 and M2 is a 4*4 matrix whose each element is a function of r =i*constant
the elements of matrices are in the form of some Bessel’s functions and quite long. I decided to store each element under a new name to avoid complications.
I also tried using a for loop similar to
(int i = 1; i <= 20; i++) {
cout << i << endl;
}
int product = 0;
for (int i = 0; i <= 20; i++) {
cout << i << endl;
product function of the matrices goes here;
}
Would this be a reasonable approach? I tried using Matlab with a simple matrix to be multiplied 20 times and it failed. Do you have any suggestion for writing a program that can multiply two matrices 20 times with iterating their elements each time?
AnswerHi Shirin
Write a program that multiplies a n/n matrix with another n/n matrix and put the thing in a loop as you have said which will iterate 20 times.
You can have a look at this link if you have any problem regarding multiplication of matrix.
http://www.scodz.com/ViewProgram.php?uid=2&link=6
Try it once and if you fail do let me know so that I can give you more hints about doing the same.
regards
Joydeep Bhattacharya
http://www.scodz.com