File: testmatrix2.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 (42 lines) | stat: -rw-r--r-- 658 bytes parent folder | download | duplicates (2)
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
require 'narray'
#require 'irb/xmp'
# xmp :: http://www.ruby-lang.org/en/raa-list.rhtml?name=xmp
def xp(s)
  begin
    puts s+" #=>"
    p eval(s)
  rescue
    puts $!
  end
  puts
end

$m1 = NMatrix.float(2,2).indgen!
$m2 = NMatrix[[0,1.2],[1.5,0]]

$v1 = NVector[0.5,1.5]
$v2 = NVector.float(2,2).indgen!

$a  = NArray.float(2,2).indgen!

xp '$m1'
xp '$m1.inverse'
xp '$m2'
xp '$m1*$m2'
xp '$m2*$m1'
xp '$m1+$m2'
xp '3.14*$m1'
xp '$m2*1.25'
xp '$v1'
xp '$v2'
xp '1.25*$v1'
xp 'NMath.sqrt($v2**2)'
xp '$v1*$v2'
xp '$m1*$v1'
xp '$v2*$m2'
xp '$m1.diagonal([98,99])'
xp 'NMatrix.float(4,3).unit'

puts "\n=== following will fail ...\n"
xp '$m1+$v1'
xp '$m1+1'