Addition of matrices
Definition
For general matrices A and B
the addition operator is defined if and only if they have the same order; m1 = m2 = m and n1 = n2 = n.
Matrix addition is an example of binary operation on the set of matrices of the same order.
plus
operator
Import the plus
operator in the namespace by doing
=> (require '[kigubkur.op [plus :refer [plus]]])
Examples using plus
Example 1
=> (def A [[2 4]
[3 2]])
=> (def B [[1 3]
[-2 5]])
=> (plus A B)
[[3 7]
[1 7]]
Example 2
=> (def A [[3 1 -1]
[2 3 0]])
=> (def B [[2 5 1]
[-2 3 (/ 1 2)]])
=> (plus A B)
[[5 6 0]
[0 6 1/2]]
Example 3
=> (def A [[-1 4 -6]
[8 5 16]
[2 8 5]])
=> (def B [[12 7 6]
[8 0 5]
[3 2 4]])
=> (plus A B)
[[11 11 0]
[16 5 21]
[5 10 9]]
Example 4
=> (def A [[1 2 -3]
[5 0 2]
[1 -1 1]])
=> (def B [[3 -1 2]
[4 2 5]
[2 0 3]])
=> (plus A B)
[[4 1 -1]
[9 2 7]
[3 -1 4]]
Basic properties of matrix addition
Given,
General form | Example |
1. Commutative Law
=> (def A [[80 60]
[75 65]
[90 85]])
=> (def B [[90 50]
[70 55]
[75 75]])
=> (= (plus A B) (plus B A))
true
2. Associative Law
=> (def C [[95 70]
[70 60]
[80 70]])
=> (= (plus (plus A B) C) (plus A (plus B C)))
true
3. Existence of additive identity
=> (def O [[0 0]
[0 0]
[0 0]])
=> (= (plus A O) (plus O A) A)
true
4. The existence of additive inverse
=> (def minusA [[-80 -60]
[-75 -65]
[-90 -85]])
=> (= (plus A minusA) (plus minusA A) O)
true