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

AI Thread 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: 141
  • 2.PNG
    2.PNG
    809 bytes · Views: 146
  • 3.PNG
    3.PNG
    1.9 KB · Views: 131
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Replies
25
Views
2K
Replies
5
Views
3K
Replies
9
Views
2K
Replies
15
Views
4K
Replies
21
Views
3K
Replies
22
Views
4K
Back
Top