Not Yet Answered # multiplication of two matrices using array

TotoTitus 6 Lerner 582 OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...

0

Any code?

First, should be extremely keen at multiplying matrices.

http://www.intmath.com/Matrices-determinants/4_Multiplying-matrices.php#matops

Just as a hint: All you need is 3 FOR loops for the main calculations.

0

I'd create a class to represent a matrix. At a minimum I'd use 3 data, two ints-one each for number of rows and number of columns to use and a pointer to pointer to type. I'd get the number of rows and columns for a given matrix and then use dynamic memory to declare a 2dimensional array using the pointer to pointer to type. Default and nondefault constructors in addition to explicit destructor, explicit assignment operator and explicit copy operator will be needed. Then I would declare either a class method or a friend function to implement the multiplication process. Multiplication of two matrixes A and B will be represented as A * B. The product of the multiplication will be a new matrix having the same number of rows as A and the same number of columns as B. The product matrix will be calculated in local variable declared with dynamic memory returned from the function similar to:

Matrix & operator *(const Matrix &);

so syntax of a call can be:

C = A * B.

By mathematical definition the product can only be generated if the number of columns of A equals the number of rows of B, so that will need to be tested before proceeding.

The basic mechanism for multiplication will follow the traditional mathematical model where each element of the product matrix, Cij, will be the sum of the products of the elements in the operands multiplied together such that:

C*[j] += A [w] * B[w][j];*

where w can vary from zero to the number of columns in A. Then to generate each element of C you can use a three level nested loop where:

a) the outer loop keeps track of an int variable, call it i, that represents the row of C, which can vary from zero to less than the number of rows in C,

b) the middle loop keeps track of an int variable, call it j, that represents the column of C, which can vary from zero to less than the number of columns in C, and

c) the innermost loop keeps track of an int variable, call it w to be consistent with the above discussion, which varies from 0 to less than the number of columns in A.

*Edited 6 Years Ago by Lerner*: n/a

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

I don’t want at this stage work on a big separate project as I've already got plenty ...

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`