473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What is my teacher asking for? Matrices...

64
This program adds two square matrices - Algorithm 1-3, Page 35.
Change it to implement the generalized algorithm to add two m x n
matrices.


Matrices, in general, are not square or n x n (n-by-n). The number of
rows may not be the same as the number of columns. Here is an example of
3 x 4 matrix.

2 3 1 0
1 4 2 -1
0 -2 2 3

You are asked to change that function so that it can add any two general
matrices, of the same dimensions.
Jul 10 '07 #1
5 1874
r035198x
13,262 8TB
This program adds two square matrices - Algorithm 1-3, Page 35.
Change it to implement the generalized algorithm to add two m x n
matrices.


Matrices, in general, are not square or n x n (n-by-n). The number of
rows may not be the same as the number of columns. Here is an example of
3 x 4 matrix.

2 3 1 0
1 4 2 -1
0 -2 2 3

You are asked to change that function so that it can add any two general
matrices, of the same dimensions.
Did you read the page that was provided?
Jul 10 '07 #2
td0g03
64
Did you read the page that was provided?
Yeah, let me post it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #define SIZE 10
  6.  
  7. void addMatrix( int m1[][SIZE], 
  8.                 int m2[][SIZE], 
  9.                 int size,     
  10.                 int m3[][SIZE] );
  11.  
  12. void printMatrix( int m[][SIZE], int size );
  13.  
  14. int main ( void )
  15. {
  16.     int size = 3;
  17.     int m1[SIZE][SIZE] = 
  18.         {
  19.             {  2,  0,  5 },
  20.             {  3,  1, 10 },
  21.             {  0,  4,  1 }
  22.         };
  23.  
  24.     int m2[SIZE][SIZE] = 
  25.         {
  26.             {  0,  1,  3},
  27.             {  2,  0,  1},
  28.             {  6,  1,  8}
  29.         };
  30.  
  31.     int m3[SIZE][SIZE];
  32.  
  33.     addMatrix( m1, m2, size, m3 );
  34.  
  35.     printf( "\nAdd two matrices:\n" );
  36.     printf( "\nMatrix 1: \n" );
  37.     printMatrix( m1, size );
  38.     printf( "\nMatrix 2: \n" );
  39.     printMatrix( m2, size );
  40.     printf( "\nTheir sum: \n" );
  41.     printMatrix( m3, size );
  42.  
  43.     return 0;
  44. }
  45.  
  46. /* ================== addMatrix  ================== 
  47.       Add m1 and m2, and place results in m3 
  48.       Pre:    m1 and m2 have data; 
  49.               size - the number of columns and rows
  50.       Post:   matrices added, result in m3
  51.       Return: nothing
  52. */
  53. void addMatrix( int m1[][SIZE], 
  54.                 int m2[][SIZE], 
  55.                 int size,     
  56.                 int m3[][SIZE] )
  57. {
  58.     int r;
  59.     int c;
  60.  
  61.     for( r = 0; r < size; r++ )
  62.         for( c = 0; c < size; c++ )
  63.             m3[r][c] = m1[r][c] + m2[r][c];
  64.  
  65.     return;
  66. } /* addMatrix */
  67.  
  68. /* ================== printMatrix  ================ 
  69.       Print matrix
  70.       Pre:    m has data; 
  71.               size - the number of columns and rows
  72.       Post:   matrix m printed
  73.       Return: nothing
  74. */
  75. void printMatrix( int m[][SIZE], int size )
  76. {
  77.     int r;
  78.     int c;
  79.  
  80.     for( r = 0; r < size; r++ )
  81.     {
  82.         for( c = 0; c < size; c++ )
  83.             printf( "%5d ", m[r][c] );
  84.         printf( "\n" );
  85.     }
  86.     printf( "\n" );
  87.  
  88.     return;
  89. } /* printMatrix */
  90.  
Jul 10 '07 #3
td0g03
64
Did you read the page that was provided?

Opps, i don't have the book, but it just shows a picture from what I remember. Of two matrices being added and having a sum. Like my program above.
Jul 10 '07 #4
This program adds two square matrices - Algorithm 1-3, Page 35.
Change it to implement the generalized algorithm to add two m x n
matrices.


Matrices, in general, are not square or n x n (n-by-n). The number of
rows may not be the same as the number of columns. Here is an example of
3 x 4 matrix.

2 3 1 0
1 4 2 -1
0 -2 2 3

You are asked to change that function so that it can add any two general
matrices, of the same dimensions.

What exactly is your problem? Are you confused about Matrices, Matrix Addition, Implementing Matrix operations in code?

If you want to know about Matrices google them and you will find all the info you need.

If you have a coding issue ask a specific question. You will get a reply.
Jul 10 '07 #5
tnga
27
maybe start here

Matrices
Jul 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nils Wagner | last post by:
Hi all, Has someone written a C binding to transfer matrices from C to Python and vice versa ? Any pointer would be appreciated. Nils
33
by: bissatch | last post by:
Hi, I fully understand the purpose of an alt attribute within a <img> tag but why would you use a title or summary attribute within, for example, a <p> tag. I have read books recommending that I...
3
by: Prototipo | last post by:
Hi! I need to dynamically create X vectors of matrices (with a known size of 5x5). It's like a three-dimensional matrix with 2 known dimensions and the third unknown. I have something like: ...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
5
by: Mark Ingram | last post by:
Right, ive got the following array with which to setup a color matrix. bm = 1; bm = 0; bm = 0; bm = 0; bm = 0; bm = 0; bm = 1; bm = 0; bm = 0; bm = 0; bm = 0; bm = 0; bm = 1; bm = 0; bm = 0; bm...
1
emaghero
by: emaghero | last post by:
Does anybody know an algorithm for the fast multiplication of three n-x-n symmetric matrices? I have an algorithm, which I'm not too pleased with, that does the job. Does anybody know a faster...
9
by: tomamil | last post by:
imagine that you have different matrices with different names and you want to perform the same action with each of them. is it possible to put their names into some array and to create a loop that...
1
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
2
by: debiasri | last post by:
I have to devide a matrix in variable no of matrices with each having variable no of rows. Like I have to devide a matrix with dim.9X19 into say 4 matrices with row nos 1,6,6,6 respectively, and I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.