cross_product()是Ruby中的內置方法,返回給定向量的交叉產品
用法: vec1.cross_product(vectors)
參數:該函數接受向量作為參數
返回值:返回給定向量的交叉產品
例子1:
#Ruby program for cross_prodcut() method in Vector
#Include matrix
require "matrix"
#Initialize the vector
vec1
= Vector[1, 2, 3] vec2 = Vector[2, 1, 4]
#Prints the cross prodcut of vectors
puts vec1.cross_product(vec2)
輸出:
Vector[5, 2, -3]
例子2:
#Ruby program for cross_prodcut() 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 prodcut of vectors
puts vec1.cross_product(vec2, vec3)
輸出:
Vector[7, -5, -3, 3]
相關用法
- Ruby Vector zero()用法及代碼示例
- Ruby Vector eql?()用法及代碼示例
- Ruby Vector r()用法及代碼示例
- Ruby Vector zero?()用法及代碼示例
- Ruby Vector angle_with()用法及代碼示例
- Ruby Vector inner_product()用法及代碼示例
- Ruby Vector independent?用法及代碼示例
- Ruby Vector covector()用法及代碼示例
- Ruby Vector component()用法及代碼示例
- Ruby Vector elements()用法及代碼示例
- Ruby Vector size()用法及代碼示例
- Ruby Vector to_matrix()用法及代碼示例
- Ruby Vector round()用法及代碼示例
- Ruby Vector hash()用法及代碼示例
- Ruby Vector norm()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Vector cross_product() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。