Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Vector inner_product() function

  • Last Updated : 21 Jan, 2021

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




#Ruby program for inner_product() method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vector
    vec1
    = Vector[1, 2] vec2 = Vector[2, 1]
 
#Prints the dot product of vectors
                          puts vec1.inner_product(vec2)

Output

4

Example 2

Ruby




#Ruby program for inner_product() method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vector
    vec1
    = Vector[1, 2, 3] vec2 = Vector[2, 1, 4]
 
#Prints the dot product of vectors
                             puts vec1.inner_product(vec2)

Output

16

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :