File: testcomplex.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 (35 lines) | stat: -rw-r--r-- 643 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
require 'narray'

def testop(a,b)
  print "a = "; p a
  print "b = "; p b
  print "a+b = "; p a+b
  print "a-b = "; p a-b
  print "a*b = "; p a*b
  print "a/b = "; p a/b
  print "a**b = "; p a**b
end

a = NArray.complex(4,1).indgen!.sbt!(-1) + 0.25.im
b = NArray.complex(1,3).indgen!.add!(-0.5).mul!(0.5.im)
testop(a,b)

# compare a/b with real-number operation
# a = NArray(4,1).indgen!.sbt!(-1)
# b = NArray(1,3).fill!(1)
# c = b*b + b*b
# p ( (a*b + 0*b)/c )
# p ( (0*b - a*b)/c )

def testimag(a)
  print "a.real = "
  p a.real
  print "a.imag = "
  p a.imag
  print "a.angle = "
  p a.angle
  print "a.conj = "
  p a.conj
end

testimag a