红宝石 |向量无关?函数
独立的?是 Ruby 中的一个内置方法,如果给定的向量是线性独立的,则返回 true,否则返回 false
Syntax: Vector.independent?(vectors)
Parameters: The function accepts vectors as parameter
Return Value: It returns true if given vectors are linearly independent otherwise false.
示例 1 :
#Ruby program for independent ? () method in Vector
#Include matrix
require "matrix"
#Initialize the vector
vec1
= Vector[1, 2] vec2 = Vector[2, 1]
#Check if vectors are linearly independent or not
Vector.independent
? (vec1, vec2)
输出:
true
示例 2 :
#Ruby program for independent ? () method in Vector
#Include matrix
require "matrix"
#Initialize the vector
vec1
= Vector[1, 2] vec2 = Vector[2, 4]
#Check if vectors are linearly independent or not
Vector.independent
? (vec1, vec2)
输出:
false