Ruby | Matrix – method
Last Updated :
07 Jan, 2020
The – is an inbuilt method in Ruby returns a matrix which has the subtraction of two matrix mat1 and mat2.
Syntax: mat1 – mat2
Parameters: The function need two matrix mat1 and mat2 which are to be subtracted.
Return Value: It returns the resultant matrix after subtraction.
Example 1:
require "matrix"
mat1 = Matrix[[ 1 , 2 , 6 ], [ 3 , 4 , 8 ], [ 12 , 1 , 3 ]]
mat2 = Matrix[[ 1 , 2 , 6 ], [ 3 , 4 , 8 ], [ 12 , 1 , 3 ]]
puts mat1 - mat2
|
Output:
Matrix[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
Example 2:
require "matrix"
mat1 = Matrix[[ 1 , 21 , 6 ], [ 31 , 124 , 18 ]]
mat2 = Matrix[[ 1 , 12 , 16 ], [ 31 , 43 , 28 ]]
puts mat1 - mat2
|
Output:
Matrix[[0, 9, -10], [0, 81, -10]]
Share your thoughts in the comments
Please Login to comment...