情報学部 | 菅沼ホーム | 目次 | 索引 |
require 'matrix'
require 'matrix' x = [1.0, 2.0] a = Vector[1.0, 2.0] # a = Vector[x] b = Vector.elements([1.0, 2.0]) # b = Vector.elements(x) print "a ", a, " b ", b, "\n" # => a Vector[1.0, 2.0] b Vector[1.0, 2.0]
a = Vector[1.0, 2.0] a[0] = 5.0 b = Vector[3.0, 4.0] print "a ", a, " b ", b, "\n" # => a Vector[5.0, 2.0] b Vector[3.0, 4.0] print "a+b ", a+b, " a-b ", a-b, " 2*a ", 2*a, "\n" # => a+b Vector[8.0, 6.0] a-b Vector[2.0, -2.0] 2*a Vector[10.0, 4.0]
require 'matrix' a = Vector[1.0, 2.0] b = Vector[3.0, 4.0] print "a ", a, " b ", b, "\n" print "|a| ", a.r, " a・b ", a.inner_product(b), "\n" # => |a| 2.23606797749979 a・b 11.0
情報学部 | 菅沼ホーム | 目次 | 索引 |