Solved

C++ Help Multiplying Matrices

Posted on 2014-04-13
12
227 Views
Last Modified: 2014-04-13
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
0
Comment
Question by:college_student
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39997892
>> result matrix being f_bar would be a single number.

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:

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;
				}

Open in new window

0
 
LVL 86

Expert Comment

by:jkr
ID: 39997893
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;
	}
            

Open in new window

0
 

Author Comment

by:college_student
ID: 39997896
thanks, but this didnt work. Im getting errors
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 39997899
Um, what errors exactly?
0
 

Author Comment

by:college_student
ID: 39997900
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?
0
 

Author Comment

by:college_student
ID: 39997902
Errors:

Error      1      error C2106: '+=' : left operand must be l-value      c:\users\carlosneal\documents\visual studio 2013\projects\consoleapplication4\consoleapplication4\source.cpp      52      1      ConsoleApplication4
      2      IntelliSense: expression must be a modifiable lvalue      c:\Users\carlosneal\Documents\Visual Studio 2013\Projects\ConsoleApplication4\ConsoleApplication4\Source.cpp      52      3      ConsoleApplication4
0
 
LVL 86

Expert Comment

by:jkr
ID: 39997909
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;
            
                                            

Open in new window

0
 

Author Comment

by:college_student
ID: 39997913
still getting errors, its saying that i and j are unreferenced local variables and x is unititialized local variable
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39997922
Copy and paste error, sorry again - the snippet should be

f_bar[0][0] = 0;

	for (int i = 0; i < 6; i++)
	{
		f_bar[0][0] += V_prime_matrix[i][0] * d_prime_matrix[0][i];
		
	}

        cout << f_bar[0][0] << endl;
                                    

Open in new window


And you should of course remove the declarations of the variables you aren't using any longer, if not, you get these warnings - so that is

int main()
{
	display_opening_logo();
	cout << setw(16) << SKIP << endl;
	
	costMatrix();
	int cost_of_original_layout = f_star();
	cout << "Press <Enter> to coninue " << endl;
	cout << setw(16) << SKIP << endl;
	char ch = _getch();
	cout << "The cost of the original existing layout is " << "$" << cost_of_original_layout << endl;

	
	for (int i = 0; i < 6; i++)
	{
		f_bar[0][0] += V_prime_matrix[i][0] * d_prime_matrix[0][i];		
	}

        cout << f_bar[0][0] << endl;

	system("PAUSE");
	return 0;

}

Open in new window

0
 

Author Comment

by:college_student
ID: 39997926
Thanks it works now!!
0
 

Author Closing Comment

by:college_student
ID: 39997927
Very helpful and resourceful!!
0
 
LVL 86

Expert Comment

by:jkr
ID: 39997933
You're most welcome ;o)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 79
best sources to up-to-date in C++? 8 102
Why  my code (program) build with old compiler? 11 105
How do I get Window Title of all opened process? 4 32
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question