Open In App

Ruby | Vector inner_product() function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
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

 


Last Updated : 21 Jan, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads