红宝石 |矩阵 rect()函数
rect()是 Ruby 中的一个内置方法,它返回两个矩阵。返回的第一个矩阵具有矩阵的所有实数值,第二个矩阵具有矩阵中的所有虚数值。
Syntax: mat1.rect()
Parameters: The function needs the matrix whose real and imaginary values are to be returned.
Return Value: It returns two matrices which has real and imaginary values.
示例 1 :
#Ruby program for rect() method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 21 ], [ 31, 18 ]]
#Prints two matrix with real
#and imaginary values
puts mat1.rect()
输出:
Matrix[[1, 21], [31, 18]]
Matrix[[0, 0], [0, 0]]
示例 2 :
#Ruby program for rect() method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 21 ], [ 31, 18 ], [ Complex(1, 9), 1 ]]
#Prints two matrix with real
#and imaginary values
puts mat1.rect()
输出:
Matrix[[1, 21], [31, 18], [1, 1]]
Matrix[[0, 0], [0, 0], [9, 0]]