Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Matrix real() function

  • Last Updated : 07 Jan, 2020

The real() is an inbuilt method in Ruby returns a matrix with only real part in it. The other index are assigned to zero.

Syntax: mat1.real()

Parameters: The function does not takes any parameter.

Return Value: It returns a matrix with only real part.

Example 1:






#Ruby program for real() method in Matrix
  
#Include matrix
require "matrix"
  
#Initialize a matrix
    mat1
    = Matrix[[ Complex(1, 2), 21 ], [ 31, Complex(9, 12) ]]
  
#prints the real part
      puts mat1.real()

Output:

Matrix[[1, 21], [31, 9]]

Example 2:




#Ruby program for real() 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 real part
      puts mat1.real()

Output:

Matrix[[19, 12], [7, 91]]
My Personal Notes arrow_drop_up
Recommended Articles
Page :