===== Matrix Addition =====
If you need some background [[http://en.wikipedia.org/wiki/Matrix_%28mathematics%29|Go here]]
==== Basics ====
2 matrices can be added only if they have the same dimensions.
The result will be a third matrix of the same dimensions.
To perform the addition, numbers in matching postions in the 2 input matrices are added and the result is placed in the same position in the output matrix.
=== Example: Adding 2x2 Matrices === Let us add 2 matrices of dimension 2x2, let them be and .
These matrices can be added, because they are both 2x2. The result will also be 2x2.
The result is:
Addition is commutative in general for matrices, i.e. .
=== More General Approach ===
Matrix addition can be performed on matrices of any dimensions, as long as they both have the same dimensions.
Let us visualize A and B as m×n matrices.
We are going to be adding like before, but generally, sot the result is:
==== General Algorithm ====
Here's a general algorithm for adding matrices:
==== Pseudocode ====
The following psedocode adds matrices of size m×n.
addMatrix(matrixA, matrixB)
C = new Matrix( matrixA.NumberOfRows, matrixA.NumberOfColumns )
for r = 1 to matrixA.NumberOfRows
for c = 1 to matrixA.NumberOfColumns
C (r , c) = A(r , c) + B(r , c)
next c
next r
return C
end
<\/code>
===== Implementations =====
==== C# ====
==== VB ====
==== Python ====
==== Ruby ====
==== Javascript ====
==== Java ====
==== Squeak / Smalltalk ====
==== Scheme / Lisp ====
==== C ====
[[Category:Algorithms]]