Ruby | Vector inner_product() function
The inner_product() is an inbuilt method in Ruby returns dot product of given vectors.
Syntax: vec1.inner_product(vec2)
Parameters: The function accepts a single vector as parameters
Return Value: It returns dot product of given vectors
Example 1:
Ruby
require "matrix"
vec1
= Vector[ 1 , 2 ] vec2 = Vector[ 2 , 1 ]
puts vec1.inner_product(vec2)
|
Output:
4
Example 2:
Ruby
require "matrix"
vec1
= Vector[ 1 , 2 , 3 ] vec2 = Vector[ 2 , 1 , 4 ]
puts vec1.inner_product(vec2)
|
Output:
16
Last Updated :
21 Jan, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...