answersLogoWhite

0


Best Answer

Addition of two matrices is simply performed by iterating over all of the elements and adding elements with like indices together. A c code snippet...

for (i=0; i<N; i++) for (j=0; j<M; j++) c[i][j] = a[i][j] + b[i][j];

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

It works for 1 dimensional arrays of virtually any size (in this case it's 10);

#include

using std::cout;
using std::endl;

int main()
{
const int size = 5;
int arr1[size] = {1, 3, 5, 7, 9};
cout << endl << "First 1D matrix is: ";
for (int i = 0; i < size; i++)
{
cout << endl << arr1[i];

}

int arr2[size] = {2, 4, 6, 8, 10};
cout << endl << "Second 1D matrix is: ";
for (int j = 0; j < size; j++)
{
cout << endl << arr2[j];

}

int sum[size] = {0};
cout << endl << "Sum of these two matrices is a matrix with elements: "
for (int k = 0; k < size; k++)
{
sum[k] = arr1[k] + arr2[k];
cout << endl << k << " element is: " << sum[k];

}

system("PAUSE");
return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

c[i][j]= a[i][j] + b[i][j];

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write an algorithm for addition of two matrices?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write an algorithm for multiplication of two sparse matrices?

how to multiply two sparse matrices


What is algorithm to multiply two matrices?

a,b,c,d,


A Write the algorithm to concatenate two given strings?

a write the algorithm to concatenate two given string


How do you develop a JAVA program that computes matrices?

Matrices can't be "computed" as such; only operations like multiplication, transpose, addition, subtraction, etc., can be done. What can be computed are determinants. If you want to write a program that does operations such as these on matrices, I suggest using a two-dimensional array to store the values in the matrices, and use for-loops to iterate through the values.


Write flowchart searching algorithm?

flow chart to swap two number


How do you add two matrices using Linux shell script?

write ashell script to add awo matrix using array.


These matrices represent the coordinates of two figures in the plane. Is the product of these matrices defined Answer yes or no?

no


What is commuting use?

Commuting in algebra is often used for matrices. Say you have two matrices, A and B. These two matrices are commutative if A * B = B * A. This rule can also be used in regular binary operations(addition and multiplication). For example, if you have an X and Y. These two numbers would be commutative if X + Y = Y + X. The case is the same for X * Y = Y * X. There are operations like subtraction and division that are not commutative. These are referred to as noncommutative operations. Hope this helps!!


Flow chart for addition of two matrices?

For the resulting matrix, just add the corresponding elements from each of the matrices you add. Use coordinates, like "i" and "j", to loop through all the elements in the matrices. For example (for Java; code is similar in C):for (i = 0; i


Is the set of all 2x2 invertible matrices a subspace of all 2x2 matrices?

I assume since you're asking if 2x2 invertible matrices are a "subspace" that you are considering the set of all 2x2 matrices as a vector space (which it certainly is). In order for the set of 2x2 invertible matrices to be a subspace of the set of all 2x2 matrices, it must be closed under addition and scalar multiplication. A 2x2 matrix is invertible if and only if its determinant is nonzero. When multiplied by a scalar (let's call it c), the determinant of a 2x2 matrix will be multiplied by c^2 since the determinant is linear in each row (two rows -&gt; two factors of c). If the determinant was nonzero to begin with c^2 times the determinant will be nonzero, so an invertible matrix multiplied by a scalar will remain invertible. Therefore the set of all 2x2 invertible matrices is closed under scalar multiplication. However, this set is not closed under addition. Consider the matrices {[1 0], [0 1]} and {[-1 0], [0 -1]}. Both are invertible (in this case, they are both their own inverses). However, their sum is {[0 0], [0 0]}, which is not invertible because its determinant is 0. In conclusion, the set of invertible 2x2 matrices is not a subspace of the set of all 2x2 matrices because it is not closed under addition.


Write an addicion story for two 3-digit number?

write an addition story for two 3-digit numbers. write the answer to your story


Why are matrices used for representation while programming?

Let me correct you: two-dimensional arrays are used in programming to represent matrices. (Matrices are objects of mathematics, arrays are objects of programming.)