Question

In: Computer Science

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.

Solutions

Expert Solution

CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace StrassenMultiplication
{
    class Exercise
    {
        static void Main(string[] args)
        {
            int i, j,m,n;
            Console.WriteLine("Enter the Number of Rows and Columns : ");
            m = Convert.ToInt32(Console.ReadLine());
            n = Convert.ToInt32(Console.ReadLine());
            int[,] a = new int[m, n];
            Console.WriteLine("Enter the First Matrix");
            for (i = 0; i < m; i++)
            {
                for (j = 0; j < n; j++)
                {
                    a[i, j] = int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine("First matrix is:");
            for (i = 0; i < m; i++)
            {
                for (j = 0; j < n; j++)
                {
                    Console.Write(a[i, j] + "\t");
                }
                Console.WriteLine();
            }
            int[,] b = new int[m, n];
            Console.WriteLine("Enter the Second Matrix");
            for (i = 0; i < m; i++)
            {
                for (j = 0; j < n; j++)
                {
                    b[i, j] = int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine("Second Matrix is :");
            for (i = 0; i < 2; i++)
            {
                for (j = 0; j < 2; j++)
                {
                    Console.Write(b[i, j] + "\t");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Matrix Multiplication is :");
            int[,] c = new int[m, n];
            for (i = 0; i < m; i++)
            {
                for (j = 0; j < n; j++)
                {
                    c[i, j] = 0;
                    for (int k = 0; k < 2; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                    }
                }
            }
            for (i = 0; i < m; i++)
            {
                for (j = 0; j < n; j++)
                {
                    Console.Write(c[i, j] + "\t");
                }
                Console.WriteLine();
            }
        }
    }
}

Related Solutions

Strassen’s algorithm for matrix multiplication relies on using 7 multiplications (instead of 8 as in the...
Strassen’s algorithm for matrix multiplication relies on using 7 multiplications (instead of 8 as in the straightforward algorithm) to multiply a pair of 2 by 2 matrices. Explain why it is not possible to further reduce this number, 7, to anything less than 4, in multiplying a pair of 2 by 2 matrices.
Strassen’s algorithm for matrix multiplication relies on using 7 multiplications (instead of 8 as in the...
Strassen’s algorithm for matrix multiplication relies on using 7 multiplications (instead of 8 as in the straightforward algorithm) to multiply a pair of 2 by 2 matrices. Explain why it is not possible to further reduce this number, 7, to anything less than 4, in multiplying a pair of 2 by 2 matrices.
Write a verilog code for 8-bit signed multiplication using Booth algorithm and represent the RTL view...
Write a verilog code for 8-bit signed multiplication using Booth algorithm and represent the RTL view for code
Recall the Matrix Chain Multiplication Algorithm for determining the optimal parenthesization for a product of matrices....
Recall the Matrix Chain Multiplication Algorithm for determining the optimal parenthesization for a product of matrices. Provide a recursive implementation of the function void print_parenth(Matrix K[], int i, int j); that takes as input the matrix K of k values that are needed to construct the optimal parenthesization for Ai · · · Aj . Assume access to a print function that takes as input a string and prints its value. You may also assume a “+” operation for string...
1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers...
1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers a, b, c and d, where a is input by a user via the keyboard, b = 2a - 1, c = ab - 2 and d = |a - b - c|. 2.Using C++ code, write a program named q5.cpp to solve the equation 2n = 14.27 for n. 3.Using C++ code, write a program named q3.cpp to divide each of the elements...
Matrix Multiplication with Threads - C/C++ In this assignment you will use the Pthreads library to...
Matrix Multiplication with Threads - C/C++ In this assignment you will use the Pthreads library to write a program that multiplies two square arrays and compare the difference between the imperative and parallel implementations of this algorithm. Use the matrix mulltiplication algorithm. Write a program that contains three functions: (1) A function that has an integer as a parameter and returns a pointer to square array of integers (i.e. both dimensions should be equal). The function should allocate storage from...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
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?
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...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT