红宝石 |矩阵实数?()函数
real?()是 Ruby 中的一个内置方法,返回一个布尔值。如果矩阵中的所有值都是实数,则返回 true,否则返回 false。
Syntax: mat1.real?()
Parameters: The function needs the matrix which is to be checked for real values
Return Value: It returns true if it all values are real, else it returns false.
示例 1 :
#Ruby program for real ? () method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 21 ], [ 31, 18 ]]
#Prints if all values are real or not
puts mat1.real
? ()
输出:
true
示例 2 :
#Ruby program for real ? () method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 21 ], [ 31, 18 ], [ Complex(1, 9), 1 ]]
#Prints if real ? or not
puts mat1.real
? ()
输出:
false