File: testmath.rb

package info (click to toggle)
ruby-narray 0.6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: ansic: 4,498; ruby: 1,329; python: 91; makefile: 7
file content (48 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'narray'
include NMath

def pr x
  x.each{|i|
    if i.kind_of?(Complex)
      printf("%.3f%+.3fi ",i.real,i.image)
    else
      printf("%.3f ",i)
    end      
  }
  print "\n"
end

def testmath(x)
  print "x = "
  pr x
  print "sqrt(x) = "
  pr sqrt(x)
  print "sin(x) = "
  pr sin(x)
  print "cos(x) = "
  pr cos(x)
  print "tan(x) = "
  pr tan(x)
  print "sinh(x) = "
  pr sinh(x)
  print "cosh(x) = "
  pr cosh(x)
  print "tanh(x) = "
  pr tanh(x)
  print "exp(x) = "
  pr exp(x)
  print "log(x) = "
  pr log(x)
  print "log10(x) = "
  pr log10(x)
  print "atan(x) = "
  pr atan(x)
  print "atan(tan(x)) = "
  pr atan(tan(x))
end

testmath NArray.sfloat(6).indgen.div!(2)
testmath NArray.float(6).indgen.div!(2)

testmath NArray.scomplex(6).indgen.div!(2)-2 - 1.im
testmath NArray.complex(6).indgen!/5-0.5# - 0.3.im