Open In App

Ruby | Matrix real?() function

Last Updated : 07 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
The real?() is an inbuilt method in Ruby returns a boolean value. It returns true if all values in the matrix are real, else it returns 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.
Example 1: CPP
#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
    ? ()
Output:
true
Example 2: CPP
#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
    ? ()
Output:
false

Next Article

Similar Reads