kigubkur.elfun.squareroot

Elementary Function: squareroot function.

(require '[kigubkur.elfun [squareroot :refer [sqrt]]])

Examples

Squareroot of a number

=> (sqrt 2)
1.4142135623730951

Squareroot 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
=> (sqrt r)
[[1.0 1.4142135623730951 1.7320508075688772 2.0]]
=> (view c)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (sqrt c)
[[1.0] [1.4142135623730951] [1.7320508075688772] [2.0]]

Squareroot 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 (sqrt M))
[1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
[1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
[1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
[1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
Order -> 4 x 5

Squareroot 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]]}]
 [{:A22 [[6 7 8 9 10]
         [6 7 8 9 10]],
   :A21 [[1 2 3 4 5]
         [1 2 3 4 5]]}]]
=> (pprint (sqrt B))
[[{:A11 [[2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]
         [2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]
         [2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]
         [2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]
         [2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]],
   :A12 [[403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]
         [403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]
         [403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]
         [403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]
         [403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]]}]
 [{:A22 [[403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]
         [403.4287934927351 1096.6331584284585 2980.9579870417283 8103.083927575384 22026.465794806718]],
   :A21 [[2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]
         [2.718281828459045 7.38905609893065 20.085536923187668 54.598150033144236 148.4131591025766]]}]]
[[{:A11 [[1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
         [1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
         [1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
         [1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
         [1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]],
   :A12 [[2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]
         [2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]
         [2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]
         [2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]
         [2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]]}]
 [{:A22 [[2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]
         [2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795]],
   :A21 [[1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]
         [1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979]]}]]

sqrt

(sqrt X)

Calculate the squareroot of a number or every element of a matrix or a block (i.e. element-wise squareroot).

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

Note that

if x ∈ {##NaN, ##Inf, ##-Inf, <0}, returns ##NaN,

otherwise, returns √x.