kigubkur.mod.changesign
Modify: to opposite sign of a number or all the elements (numbers) of a kigubkur© matrix (block included).
chs
(require '[kigubkur.mod [changesign :refer [chs]]])
Examples
Change sign of a number
=> (chs -1)
1
=> (chs 1)
-1
Change sign of a vector
=> (def r [[1 -2 -3 4]])
=> (def c [[-1][-2][3][4]])
=> (view r)
[1 -2 -3 4]
Order -> 1 x 4
=> (chs r)
[[-1 2 3 -4]]
=> (view c)
[-1]
[-2]
[3]
[4]
Order -> 4 x 1
=> (chs c)
[[1] [2] [-3] [-4]]
Change sign of a matrix
=> (def M [[1 2 3 4 5] [-1 -2 -3 -4 -5] [1 -2 3 -4 5] [-1 2 -3 4 -5]])
=> (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 (chs 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
Change sign of a block
(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[1 2 3 4 5 6 7 8 9 10]
[-1 -2 -3 -4 -5 -6 -7 -8 -9 -10]
[-1 2 -3 4 -5 6 -7 8 -9 10]
[1 -2 3 -4 5 -6 7 -8 9 -10]
[1 2 -3 4 5 -6 7 8 -9 10]
[1 2 3 -4 5 6 7 -8 9 10]
[1 2 3 4 -5 6 7 8 9 -10]])
=> (def B (block L 5))
=> (pprint B)
[[{:A11 [[1 2 3 4 5]
[-1 -2 -3 -4 -5]
[-1 2 -3 4 -5]
[1 -2 3 -4 5]
[1 2 -3 4 5]],
:A12 [[6 7 8 9 10]
[-6 -7 -8 -9 -10]
[6 -7 8 -9 10]
[-6 7 -8 9 -10]
[-6 7 8 -9 10]]}]
[{:A21 [[1 2 3 -4 5]
[1 2 3 4 -5]],
:A22 [[6 7 -8 9 10]
[6 7 8 9 -10]]}]]
=> (pprint (chs B))
[[{:A11 [[-1 -2 -3 -4 -5]
[1 2 3 4 5]
[1 -2 3 -4 5]
[-1 2 -3 4 -5]
[-1 -2 3 -4 -5]],
:A12 [[-6 -7 -8 -9 -10]
[6 7 8 9 10]
[-6 7 -8 9 -10]
[6 -7 8 -9 10]
[6 -7 -8 9 -10]]}]
[{:A21 [[-1 -2 -3 4 -5]
[-1 -2 -3 -4 5]],
:A22 [[-6 -7 8 -9 -10]
[-6 -7 -8 -9 10]]}]]
chs
(chs x)
Changes to opposite sign of a number or every element of a matrix or a block (i.e. element-wise). Therefore, given a scalar or a matrix (or block) X, this function returns its negative, -X.
Syntax: (chs x)
Note: if x ∈ {##NaN
, ##Inf
, ##-Inf
}, returns ##NaN
.
neg
(neg X)
Given a matrix X, this function returns its negative, -X.
Note: neg
is same as chs
it exists because its name can sometimes be more intuitive.