How can I effectively perform matrix operations in C programming language?

3 replies · 2K views · last reply
Henry R
Messages
25
Reaction score
0
Good day everyone. I'm learning C language at the moment. Plus, matrix is bit harder. It just I couldn't understand how to write it in C programming language. Plus, it's maths calculations.
I have to use C language for this, not C++.Here's the question :
A matrix is an array of numbers which can be used in calculations. You are required to create a two 2 x 2 matrices, and perform a matrix addition and a matrix multiplication.

View attachment 3477

a) The sum of A and B, denoted by A+B, is the m x n matrix, which is obtained by adding elements in the corresponding positions.
View attachment 3478

b) The product of A and B denoted by AB, is m × n matrix with (i,j)th entry equal to the sum of the products of the corresponding elements from the ith row of A and the jth column of B. In other words, if AB = [cij], then

View attachment 3479
 
Attachments
  • Text defining two m x n matrices A = [a_ij] and B = [b_ij], with A = (3 1; 4 2) and B = (2 3; 1 5) written as 2 x 2 arrays.
    1.PNG
    1.4 KB · Views: 199
  • Text reading 'The sum of A and B is:' followed by a 2 x 2 matrix with rows 5 4 and 5 7, in parentheses.
    2.PNG
    809 bytes · Views: 202
  • Matrix product formula c_ij = a_i1 b_1j + a_i2 b_2j + ... + a_ik b_kj, equal to the sum from t = 1 to k of a_it b_tj, followed by the product of A and B as a 2 x 2 matrix with rows 7 14 and 10 22.
    3.PNG
    1.9 KB · Views: 187
The following should create a 2x2 array

Code:
int a[2][2] = {{1,2},{3,4}};
//where a[0][0] = 1 , a[0][1] = 1 , a[1][0] = 1 , a[1][1] = 1

to get or a set an element you can use $a[j]$ where $i$ represents the row and $j$ represents the column.
 
ZaidAlyafey said:
The following should create a 2x2 array

Code:
int a[2][2] = {{1,2},{3,4}};
//where a[0][0] = 1 , a[0][1] = 1 , a[1][0] = 1 , a[1][1] = 1

to get or a set an element you can use $a[j]$ where $i$ represents the row and $j$ represents the column.


How about the code? I mean, can you show me the complete code?;) Sorry, if this sound annoying. But, I try my best on programming.
 
Can you post your attempt ? then if there are mistakes we can correct them.