Ruby | Matrix trace() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The trace() is an inbuilt method in Ruby returns the trace i.e., sum of diagonal elements of the matrix. Syntax: mat1.trace() Parameters: The function needs the matrix whose trace is to be returned. Return Value: It returns the trace. Example 1: Ruby # Ruby program for trace() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[3, 12], [2, 8]] # Prints the trace puts mat1.trace() Output: 11 Example 2: Ruby # Ruby program for trace() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 0, 6], [6, 1, 7], [1, 2, 19]] # Prints the trace puts mat1.trace() Output: 21 Comment More infoAdvertise with us Next Article Ruby | Matrix trace() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix tr() function The tr() is an inbuilt method in Ruby returns the trace i.e., sum of diagonal elements of the matrix. Syntax: mat1.tr() Parameters: The function needs the matrix whose trace is to be returned. Return Value: It returns the trace. Example 1: Ruby # Ruby program for tr() method in Matrix # Include matr 1 min read Ruby | Matrix t() function The t() is an inbuilt method in Ruby returns the transpose of the matrix. Syntax: mat1.t() Parameters: The function needs the matrix to be transposed. Return Value: It returns the transposed matrix. Example 1: Ruby # Ruby program for t() method in Matrix # Include matrix require "matrix" # 1 min read Ruby | Matrix vstack() function The vstack() is an inbuilt method in Ruby returns a new matrix resulting by stacking vertically the receiver with the given matrices. It requires a matrix which is stacked upon vertically. Syntax: mat1.vstack(mat2) Parameters: The function needs a matrix which is to be stacked vertically. Return Val 1 min read Ruby | Matrix transpose() function The transpose() is an inbuilt method in Ruby returns the transpose of the matrix. Syntax: mat1.transpose() Parameters: The function needs the matrix to be transposed. Return Value: It returns the transposed matrix. Example 1: Ruby # Ruby program for transpose() method in Matrix # Include matrix requ 1 min read Ruby | Matrix square?() function The square?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a square matrix, else it returns false. Syntax: mat1.square?() Parameters: The function needs the matrix to be checked for square matrix or not. Return Value: It returns true if it is a square matrix, else i 1 min read Like