kigubkur.elfun.reciprocal

Elementary Function: reciprocal of a number or all the elements (numbers) of a kigubkur© matrix (block included).

  • reci
(require '[kigubkur.elfun [reciprocal :refer [reci]]])

Examples

Reciprocal of a number

=> (reci 2.0)
0.5

Reciprocal 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
=> (reci r)
[[1 -1/2 -1/3 1/4]]
=> (view c)
[-1]
[-2]
[3]
[4]
Order -> 4 x 1
=> (reci c)
[[-1] [-1/2] [1/3] [1/4]]

Reciprocal 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 (reci M))
[1 1/2 1/3 1/4 1/5]
[-1 -1/2 -1/3 -1/4 -1/5]
[1 -1/2 1/3 -1/4 1/5]
[-1 1/2 -1/3 1/4 -1/5]
Order -> 4 x 5

Reciprocal 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 (reci B))
[[{:A11 [[1 1/2 1/3 1/4 1/5]
         [-1 -1/2 -1/3 -1/4 -1/5]
         [-1 1/2 -1/3 1/4 -1/5]
         [1 -1/2 1/3 -1/4 1/5]
         [1 1/2 -1/3 1/4 1/5]],
   :A12 [[1/6 1/7 1/8 1/9 1/10]
         [-1/6 -1/7 -1/8 -1/9 -1/10]
         [1/6 -1/7 1/8 -1/9 1/10]
         [-1/6 1/7 -1/8 1/9 -1/10]
         [-1/6 1/7 1/8 -1/9 1/10]]}]
 [{:A21 [[1 1/2 1/3 -1/4 1/5]
         [1 1/2 1/3 1/4 -1/5]],
   :A22 [[1/6 1/7 -1/8 1/9 1/10]
         [1/6 1/7 1/8 1/9 -1/10]]}]]

reci

(reci X)

Reciprocal of a number or every element of a matrix or a block. Therefore, given a matrix X, this function returns its reciprocal, 1/X.

Syntax: (reci X) s.t X is a scalar or a kigubkur© matrix (or both blocks)

Note: if x ∈ {##NaN, ##Inf, ##-Inf}, returns ##NaN.