Module: NMath

Defined in:
lib/narray_ext.rb

Constant Summary collapse

PI =
Math::PI
E =
Math::E

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acot(x) ⇒ Object



210
211
212
# File 'lib/narray_ext.rb', line 210

def acot x
  atan(1/x.to_f)
end

.acoth(x) ⇒ Object



213
214
215
# File 'lib/narray_ext.rb', line 213

def acoth x
  atanh(1/x.to_f)
end

.acsc(x) ⇒ Object



184
185
186
# File 'lib/narray_ext.rb', line 184

def acsc x
  asin(1/x.to_f)
end

.acsch(x) ⇒ Object



187
188
189
# File 'lib/narray_ext.rb', line 187

def acsch x
  asinh(1/x.to_f)
end

.asec(x) ⇒ Object



197
198
199
# File 'lib/narray_ext.rb', line 197

def asec x
  acos(1/x.to_f)
end

.asech(x) ⇒ Object



200
201
202
# File 'lib/narray_ext.rb', line 200

def asech x
  acosh(1/x.to_f)
end

.cot(x) ⇒ Object



204
205
206
# File 'lib/narray_ext.rb', line 204

def cot x
  1/tan(x)
end

.coth(x) ⇒ Object



207
208
209
# File 'lib/narray_ext.rb', line 207

def coth x
  1/atanh(x)
end

.covariance(x, y, *ranks) ⇒ Object

Statistics



218
219
220
221
222
223
224
225
226
227
# File 'lib/narray_ext.rb', line 218

def covariance(x,y,*ranks)
  x = NArray.to_na(x) unless x.kind_of?(NArray)
  x = x.to_type(NArray::DFLOAT) if x.integer?
  y = NArray.to_na(y) unless y.kind_of?(NArray)
  y = y.to_type(NArray::DFLOAT) if y.integer?
  n = x.rank_total(*ranks)
  xm = x.accum(*ranks).div!(n)
  ym = y.accum(*ranks).div!(n)
  ((x-xm)*(y-ym)).sum(*ranks) / (n-1)
end

.csc(x) ⇒ Object

Trigonometric function



178
179
180
# File 'lib/narray_ext.rb', line 178

def csc x
  1/sin(x)
end

.csch(x) ⇒ Object



181
182
183
# File 'lib/narray_ext.rb', line 181

def csch x
  1/sinh(x)
end

.sec(x) ⇒ Object



191
192
193
# File 'lib/narray_ext.rb', line 191

def sec x
  1/cos(x)
end

.sech(x) ⇒ Object



194
195
196
# File 'lib/narray_ext.rb', line 194

def sech x
  1/cosh(x)
end

Instance Method Details

#recip(x) ⇒ Object



173
174
175
# File 'lib/narray_ext.rb', line 173

def recip x
  1/x.to_f
end