红宝石 |矩阵虚数()函数
imaginary()是 Ruby 中的一个内置方法,它返回一个只有虚数部分的矩阵。另一个索引分配为零。
Syntax: mat1.imaginary()
Parameters: The function does not takes any parameter.
Return Value: It returns a matrix with only imaginary part.
示例 1 :
#Ruby program for imaginary() method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ Complex(1, 2), 21 ], [ 31, Complex(9, 12) ]]
#prints the imaginary part
puts mat1.imaginary()
输出:
Matrix[[2, 0], [0, 12]]
示例 2 :
#Ruby program for imaginary() method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ Complex(19, 3), Complex(12, 3) ], [ Complex(7, 8), Complex(91, 2) ]]
#prints the imaginary part
puts mat1.imaginary()
输出:
Matrix[[3, 3], [8, 2]]