情報学部 | 菅沼ホーム | 目次 | 索引 |
require 'complex'
require 'complex' a = Complex(1.0, 2.0) p a # => (1.0+2.0i)
require 'complex' a = Complex(1.0, 2.0) b = Complex(3.0, 4.0) c = Complex(1, 2) d = Complex(3, 4) print "a ", a, " b ", b, " c ", c, " d ", d, "\n" # => a 1.0+2.0i b 3.0+4.0i c 1+2i d 3+4i print a + b, " ", a - b, " ", a * b, " ", a / b, "\n" # => 4.0+6.0i -2.0-2.0i -5.0+10.0i 0.44+0.07999999999999999i print c + d, " ", c - d, " ", c * d, " ", c / d, "\n" # => 4+6i -2-2i -5+10i 11/25+2/25i print 2 + b, " ", 2 - b, " ", 2 * b, " ", 2 / b, "\n" # => 5.0+4.0i -1.0-4.0i 6.0+8.0i 0.24-0.32i print a + 2, " ", a - 2, " ", a * 2, " ", a / 2, "\n" # => 3.0+2.0i -1.0+2.0i 2.0+4.0i 0.5+1.0i
require 'complex' a = Complex(1.0, 2.0) print "大きさ ", a.abs, " 偏角(ラジアン) ", a.arg, " 共役 ", a.conjugate, "\n" # => 大きさ 2.23606797749979 偏角(ラジアン) 1.1071487177940904 共役 1.0-2.0i
require 'complex' a = Complex(1.0, 2.0) print "実部 ", a.real, " 虚部 ", a.imag # => 実部 1.0 虚部 2.0
情報学部 | 菅沼ホーム | 目次 | 索引 |