Open In App

Ruby | Vector inner_product() function

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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


 


Similar Reads