Scalar multiplication of matrix

Definition

For general matrix A

matrix A

multiplication of the matrix by the scalar k is defined as

matrix kA

etimes operator

Import the etimes operator in the namespace by doing

=> (require '[kigubkur.op [etimes :refer [etimes]]])

Examples using etimes

Example 1

=> (def A [[5000 10000 6000]
           [20000 10000 10000]])
=> (etimes 0.02 A)
[[100 200 120]
 [400 200 200]]

Example 2

=> (def A [[-6 -10]
           [12 14]
           [-31 -7]])
=> (etimes 1/3 A)
[[-2 -10/3]
 [4 14/3]
 [-31/3 -7/3]]

Example 3

=> (require '[kigubkur.op [minus :refer [minus]]])
=> (def A [[2/3 1 5/3]
           [1/3 2/3 4/3]
           [7/3 2 2/3]])
=> (def B [[2/5 3/5 1]
           [1/5 2/5 4/5]
           [7/5 6/5 2/5]])
=> (def O [[0 0 0]
           [0 0 0]
           [0 0 0]])
=> (minus (etimes 3 A) (etimes 5 B)
[[0N 0N 0N]
 [0N 0N 0N]
 [0N 0N 0N]]
=> (= (minus (etimes 3 A) (etimes 5 B)) O)
true

Notice that because the elements of the matrices A and B are either integers or rational numbers the elements of the resulting matrix will not be transformed into a real number. Here, the postfix N indicates the numeric literal BigInt.

Basic properties of matrix multiplication

1. Commutative Law

matrix kA = Ak

=> (def A [[1 2 3]
           [3 -2 1]
           [4 2 1]])
=> (= (etimes 23 A) (etimes A 23))
true

2. Distributive Law

=> (require '[kigubkur.op [plus :refer [plus]]])

2.1. Given the scalar k and the matrices A and B that are of same order

matrix k (A + B) = kA + kB

=> (def k 2)
=> (def A [[8 0]
           [4 -2]
           [3 6]])
=> (def B [[2 -2]
           [4 2]
           [-5 1]])
=> (= (etimes k (plus A B)) (plus (etimes k A) (etimes k B)))
true

2.2. Given the scalars k and l and the matrix A

matrix (k + l) A = kA + lA

=> (def k 5)
=> (def l 3)
=> (def A [[-2 -10/3]
           [4 14/3]
           [-31/3 -7/3]])
=> (= (etimes (plus k l) A) (plus (etimes k A) (etimes l A)))
true