📜  红宝石 |向量 cross_product()函数

📅  最后修改于: 2022-05-13 01:54:56.829000             🧑  作者: Mango

红宝石 |向量 cross_product()函数

cross_product()是 Ruby 中的一个内置方法,返回给定向量的叉积

示例 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)


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)


输出

Vector[5, 2, -3]

示例 2

红宝石

#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)

输出

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