Ruby | Matrix ** method
Last Updated :
07 Jan, 2020
The ** is an inbuilt method in Ruby returns the matrix after the matrix is multiplied with self N times. It returns the matrix exponentiation value.
Syntax: Matrix_name ** (number)
Parameters: The function takes a mandatory parameter number which signifies the number of times it will be multiplied with self.
Return Value: It returns the resultant matrix after multiplication.
Example 1:
require "matrix"
mat = Matrix[[ 12 , 41 ], [ 61 , 81 ]]
puts mat ** 3
|
Output:
Matrix[[264333, 417298], [620858, 966615]]
Example 2:
require "matrix"
mat = Matrix[[ 1 , 2 , 6 ], [ 3 , 4 , 8 ], [ 12 , 1 , 3 ]]
puts mat ** 2
|
Output:
Matrix[[79, 16, 40], [111, 30, 74], [51, 31, 89]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...