Related Articles

Related Articles

Ruby | Matrix real?() function
  • Last Updated : 07 Jan, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

#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
    ? ()

chevron_right


Output:

true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#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
    ? ()

chevron_right


Output:

false
My Personal Notes arrow_drop_up
Recommended Articles
Page :