college_student
asked on
C++ Help Multiplying Matrices
Hello I would like help in multiplying 2 matrices in the attached code, the 2 matrices being multiplied are the V_prime_matrix[6][1] and the d_prime_matrix[1][6] and the result matrix being f_bar would be a single number.
Can anyone help me?
QAP-EE-Code.txt
Can anyone help me?
QAP-EE-Code.txt
Ooops, that formatting is downright ugly, make that
int f_bar = 0;
for (int i = 0; i < 6; i++)
{
f_bar += V_prime_matrix[x][0] * d_prime_matrix[0][i];
cout << f_bar << endl;
}
ASKER
thanks, but this didnt work. Im getting errors
Um, what errors exactly?
ASKER
why did you change it to [x][0] and [0][1]? I dont understand that.
Also shouldnt it be f_bar[x][x] or something similar, not just f_bar by itself?
Also shouldnt it be f_bar[x][x] or something similar, not just f_bar by itself?
ASKER
Errors:
Error 1 error C2106: '+=' : left operand must be l-value c:\users\carlosneal\docume nts\visual studio 2013\projects\consoleappli cation4\co nsoleappli cation4\so urce.cpp 52 1 ConsoleApplication4
2 IntelliSense: expression must be a modifiable lvalue c:\Users\carlosneal\Docume nts\Visual Studio 2013\Projects\ConsoleAppli cation4\Co nsoleAppli cation4\So urce.cpp 52 3 ConsoleApplication4
Error 1 error C2106: '+=' : left operand must be l-value c:\users\carlosneal\docume
2 IntelliSense: expression must be a modifiable lvalue c:\Users\carlosneal\Docume
Ah, I see - sorry, but then make that
f_bar[0][0] = 0;
for (int i = 0; i < 6; i++)
{
f_bar[0][0] += V_prime_matrix[x][0] * d_prime_matrix[0][i];
}
cout << f_bar[0][0] << endl;
ASKER
still getting errors, its saying that i and j are unreferenced local variables and x is unititialized local variable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks it works now!!
ASKER
Very helpful and resourceful!!
You're most welcome ;o)
That is right, in your special case the result of 'V_prime_matrix[6][1] * d_prime_matrix[1][6]' es quivalent to the scalar product (http://en.wikipedia.org/wiki/Scalar_product) - so you can rewrite your code to just one loop:
Open in new window