Open In App

Ruby | Vector cross_product() function

Improve
Improve
Like Article
Like
Save
Share
Report

The cross_product() is an inbuilt method in Ruby returns cross product of given vectors
 

Syntax: vec1.cross_product(vectors)

Parameters: The function accept vectors as parameters

Return Value: It returns cross product of given vectors 
 

Example 1:  

Ruby




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


Output

Vector[5, 2, -3]

Example 2

Ruby




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


Output

Vector[7, -5, -3, 3]

 


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