kigubkur.construct.insert

Construct a kigubkur© matrix by injection.

(require '[kigubkur.construct [insert :refer [insert]]])

Examples

Insert a number

=> (def r [[1 -2 -3 4]])
=> (def c [[-1][-2][3][4]])
=> (def M [[1 2 3 4 5] [-1 -2 -3 -4 -5] [1 -2 3 -4 5] [-1 2 -3 4 -5]])
=> (view r)
[1 -2 -3 4]
Order -> 1 x 4
=> (insert r 4 -4)
[[1 -2 -3 -4]]
 => (view c)
[-1]
[-2]
[3]
[4]
Order -> 4 x 1
=> (insert c 1 10)
[[10][-2][3][4]]
=> (view M)
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[1 -2 3 -4 5]
[-1 2 -3 4 -5]
Order -> 4 x 5
=> (view (insert M [3 2] 22))
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[1 22 3 -4 5]
[-1 2 -3 4 -5]
Order -> 4 x 5

Insert a sub-matrix

=> (view (insert M [3 1] [[0 0] [0 0]]))
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[0 0 3 -4 5]
[0 0 -3 4 -5]
Order -> 4 x 5
=> (view (insert M [3 3] [[0 0]]))
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[1 -2 0 0 5]
[-1 2 -3 4 -5]
Order -> 4 x 5
=> (view (insert M [1 1] [[0 0 0 0 0]]))
[0 0 0 0 0]
[-1 -2 -3 -4 -5]
[1 -2 3 -4 5]
[-1 2 -3 4 -5]
Order -> 4 x 5
=> (view (insert M [1 5] [[0] [0] [0] [0]]))
[1 2 3 4 0]
[-1 -2 -3 -4 0]
[1 -2 3 -4 0]
[-1 2 -3 4 0]
Order -> 4 x 5
=> (view (insert M [2 2] [[0] [0] [0]]))
[1 2 3 4 5]
[-1 0 -3 -4 -5]
[1 0 3 -4 5]
[-1 0 -3 4 -5]
Order -> 4 x 5
=> (view (insert M [3 3] [[0] [0]]))
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[1 -2 0 -4 5]
[-1 2 0 4 -5]
Order -> 4 x 5

Notice that (insert M [3 3] [[0]]) has the same result as (insert M [3 3] 0)

=> (view (insert M [3 3] [[0]]))
[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[1 -2 0 -4 5]
[-1 2 -3 4 -5]
Order -> 4 x 5

insert

(insert M ij X)

Insert an element or sub-matrix (row, column, matrix) X into desired index ij in matrix M.

M ij X
row, column scalar: i or j scalar
matrix [i j] scalar
row, column, matrix [from_i from_j] row, column, matrix