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

  • Context: MHB 
  • Thread starter Thread starter Henry R
  • Start date Start date
  • Tags Tags
    Language Programming
Click For Summary

Discussion Overview

The discussion revolves around performing matrix operations in the C programming language, specifically focusing on creating and manipulating 2x2 matrices through addition and multiplication. Participants are sharing their understanding and seeking guidance on coding these operations.

Discussion Character

  • Homework-related, Technical explanation

Main Points Raised

  • One participant expresses difficulty in understanding how to implement matrix operations in C, specifically for 2x2 matrices.
  • Another participant provides an example of how to create a 2x2 array in C, demonstrating the syntax for initializing the matrix.
  • A similar example is reiterated by a different participant, emphasizing the same initialization method and access syntax for matrix elements.
  • One participant requests a complete code example for matrix operations, indicating their struggle with programming.
  • A suggestion is made for the original poster to share their current code attempt so that others can help identify mistakes.

Areas of Agreement / Disagreement

Participants generally agree on the syntax for creating and accessing elements of a 2x2 matrix in C, but there is no consensus on the complete implementation of matrix operations as the original poster has not yet shared their code.

Contextual Notes

The discussion lacks specific details on the implementation of matrix addition and multiplication, and there are no shared code attempts from the original poster to evaluate.

Who May Find This Useful

Individuals learning C programming, particularly those interested in matrix operations and array manipulation.

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: 164
  • 2.PNG
    2.PNG
    809 bytes · Views: 170
  • 3.PNG
    3.PNG
    1.9 KB · Views: 148
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.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
6
Views
4K