红宝石 |向量 r()函数
r()是 Ruby 中的一个内置方法,它返回向量的毕达哥拉斯距离。
Syntax: vec1.r()
Parameters: The function accepts no parameter
Return Value: It Pythagorean distance of the vector
示例 1 :
# Ruby program for r() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[1, 2, 3]
# Prints pythogras of the vector
puts vec1.r()
输出:
3.7416573867739413
示例 2 :
# Ruby program for r() method in Vector
# Include matrix
require "matrix"
# Initialize the vector
vec1 = Vector[1, 1, 1]
# Prints pythogras of the vector
puts vec1.r()
输出:
1.7320508075688772