Question

In: Computer Science

Please give C++ code ASAP Matrix Multiplication Due Friday 30th October 2020 by 23:55. (2 marks)...

Please give C++ code ASAP

Matrix Multiplication Due Friday 30th October 2020 by 23:55.

For this exercise, you are to find the optimal order for multiplying a sequence of matrices. Note: you do not actually have to perform any matrix multiplications. As usual, your program will prompt for the name of an input file and the read and process the data contained in this file.

The file contains the following data. N, the number of matrices to be multiplied together N pairs of integers which are the row and column dimensions of each matrix. E.g.

The following input

3

3 4

4 2

2 5

Defines a problem in which we are to multiply three matrices, say M[0], M[1] and M[2], where:

M[0] has 3 rows and 4 columns; M[1] has 4 rows and 2 columns; M[2] has 2 rows and 5 columns.

Output for the program is the value of best(0,N), the minimum number of multiplications required to compute the matrix R = M[0]xM[1]x…xM[N‐1].

You may leave your solution as a memoized, recursive formulation if you have problems formulating the looped iterative scheme.

As usual, do not use classes or STL. Submit ex10.ext via moodle as usual where ext is one of c, cpp, java or py.

Solutions

Expert Solution

Source Code: in C++

#include <iostream>
#include <fstream>
#include <array>
#include <sstream>
#include <string>
#include <stdio.h>
#include <algorithm>

int row=0;
int col=0;
int i,j,k;
using namespace std;

int main()
{
string line;
ifstream myfile;
int x;
int arrayA[100][100] = {{0}};
int arrayB[100][100] = {{0}};
int arrayD[100][100] = {{0}};
myfile.open("numeric.txt");
  if(myfile.fail())
  {
   cerr<<"file does not exist";
  }
  cout<<"\n"<<endl;
  while(myfile.good())
   {
    while(getline(myfile,line))
     {
      istringstream stream(line);
      col=0;
      while(stream >> x)
      {
        arrayA[row][col]=x;
        col ++;
      }
        row ++;
     }

  for(int i=0;i<row;i++)
   {
     for(int j=0;j<col;j++)
     {
      cout<<arrayA[i][j]<< " " ;
    
     }
      cout<<endl;
   }
  cout<<"\n"<<endl;
 }
cout<<"first Matrix"<<endl;
        for(i=1;i<=3;i++)
        {
                for(j=0;j<3;j++)
                {
                   
                        cout<<arrayA[i][j]<<" ";
                }
                cout<<endl;
        }


        cout<<"Second Matrix"<<endl;
        for(i=2;i<5;i++)
        {
                for(j=2;j<5;j++)

                {       
                         
                        arrayB[i][j] = arrayA[i][j];
                        cout<<arrayB[i][j]<<" ";
                }
                cout<<endl;
        }
cout<<"Multiplication Result"<<endl;
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {       
                        int sum = 0;    
                        for(k=0;k<3;k++)
                        {
                                sum=sum+arrayA[i][k]*arrayB[k][j];
                        }
                    arrayD[i][j]=sum;
                 }
        }
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        cout<<arrayD[i][j]<<" ";
                }
                cout<<endl;
        }
        
return 0;
}

Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

Related Solutions

Please give Java Code ASAP Matrix Multiplication Due Friday 30th October 2020 by 23:55. (2 marks)...
Please give Java Code ASAP Matrix Multiplication Due Friday 30th October 2020 by 23:55. For this exercise, you are to find the optimal order for multiplying a sequence of matrices. Note: you do not actually have to perform any matrix multiplications. As usual, your program will prompt for the name of an input file and the read and process the data contained in this file. The file contains the following data. N, the number of matrices to be multiplied together...
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Due Friday Oct. 30th, 11:59pm (10 marks total): 1. Explain the purpose of a sequence diagram....
Due Friday Oct. 30th, 11:59pm (10 marks total): 1. Explain the purpose of a sequence diagram. . 2. Draw a sequence diagram for the online ticketing system in Assignment #3. Identify the objects, lifelines, messages, and focuses in your diagram. .
[12:18, 10/2/2020] Mohan Reddy: You are to implement a program for matrix multiplication in C++ without...
[12:18, 10/2/2020] Mohan Reddy: You are to implement a program for matrix multiplication in C++ without thread AND with thread. [12:18, 10/2/2020] Mohan Reddy: ou are to implement (M by N matrix) times (N by 1 vector) operation and see how multiple threads can speed up the computation. The resulting vector will be (M by 1 vector). See the following steps/requirements. 1. Accept M and N as keyboard input. 2. Generate a random (M by N matrix) and a random...
Can someone please solve parts c, d, e, and h ASAP? This is due tomorrow 2....
Can someone please solve parts c, d, e, and h ASAP? This is due tomorrow 2. (30 pts) Consider a production function given by: Q = 12(KL)2 – L 4 . a. (5 pts) Does this production function exhibit increasing, constant, or decreasing returns to scale? b. (5 pts) Derive the equation for the average product of labor and the marginal product of labor? c. (4 pts) Let K = 2. Find the level of L at which the marginal...
Implement function matmul() that embodies multiplication of n*n matrix in c language?(code) Can you let me...
Implement function matmul() that embodies multiplication of n*n matrix in c language?(code) Can you let me know?
Due Date: 30 October 2020 Question 1 (100 marks) Note: you must use your own words...
Due Date: 30 October 2020 Question 1 Note: you must use your own words in answering the questions; those parts copied from any source without your inputs/explanation/examples or elaborations will not be given any marks. I . The Conceptual Framework for Financial Reporting sets and discusses the objective and fundamentals that serve as the basis for developing financial accounting and reporting standards in different countries. The fundamentals are the underlying concepts of financial accounting that guide the selection of transactions,...
Please complete following c++ code asap using following prototypes complete each missing part / Linked list...
Please complete following c++ code asap using following prototypes complete each missing part / Linked list operations int getLength() const {return length;} void insertNode(College); bool deleteNode(string); void displayList() const; bool searchList(string, College &) const; }; main.cpp /*   Build and procees a sorted linked list of College objects. The list is sorted in ascending order by the college code. Assume that the college code is unique. */ #include <iostream> #include <fstream> #include <string> #include "LinkedList.h" using namespace std; void buildList(const string...
I need Q1,2 and 3 ASAP please, thanks 1. Identify three applications of integration. 2. Give...
I need Q1,2 and 3 ASAP please, thanks 1. Identify three applications of integration. 2. Give two specific examples of how we use integration to solve real-world problems. 3. Write a paragraph about how integration is applied in non-STEM disciplines. You must start a thread before you can read and reply to other threads
Please code in C /* Implements functions that operate on Stack 1. PUSH 2. POP 3....
Please code in C /* Implements functions that operate on Stack 1. PUSH 2. POP 3. isEmpty 4. PEEK 5. Size */ #include <stdio.h> #define CAPACITY 1000 //Two stacks .. for each stack we need // 1. An Array that can hold capacity of elements // 2. A top initialzied to -1 (signifying that the stak is empty at the start) //NOTE : THESE STACKS ARE OF TYPE CHAR :( ... so you need to FIX IT!!!! to int and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT