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