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

Click For Summary
The discussion centers on learning how to perform matrix addition and multiplication using the C programming language. The user is specifically tasked with creating two 2x2 matrices and implementing the required operations. For matrix addition, the sum of two matrices A and B is obtained by adding corresponding elements. For matrix multiplication, the product is calculated by summing the products of the elements from the rows of the first matrix and the columns of the second. The user requests complete code examples for these operations in C, expressing a desire for assistance in correcting any mistakes in their attempts. The conversation emphasizes the importance of understanding both the mathematical concepts and the corresponding C syntax for matrix operations.
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

  • 1.PNG
    1.PNG
    1.4 KB · Views: 155
  • 2.PNG
    2.PNG
    809 bytes · Views: 157
  • 3.PNG
    3.PNG
    1.9 KB · Views: 140
Technology news on Phys.org
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K