📜  红宝石 |向量 - 方法

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

红宝石 |向量 - 方法

是 Ruby 中的一个内置方法,返回两个向量的减法

示例 1

CPP
#Ruby program for - method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vectors
    vec1
    = Vector[1, 2] vec2 = Vector[1, 4]
 
#prints the new vector
                          puts vec1
                          - vec2


CPP
#Ruby program for - method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vectors
    vec1
    = [ 1, 4, 5 ] vec2 = [ 1, 4, 7 ]
 
#prints the new vector
                         puts vec1
                         - vec2


输出

Vector[0, -2]

示例 2

CPP

#Ruby program for - method in Vector
 
#Include matrix
require "matrix"
 
#Initialize the vectors
    vec1
    = [ 1, 4, 5 ] vec2 = [ 1, 4, 7 ]
 
#prints the new vector
                         puts vec1
                         - vec2

输出

Vector[0, 0, -2]