📜  红宝石 |向量*法

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

红宝石 |向量*法

*是 Ruby 中的一个内置方法,通过将向量乘以 x 返回一个向量

示例 1

#Ruby program for* method in Vector
  
#Include matrix
require "matrix"
  
#Initialize the vector
    vec1
    = Vector[1, 2]
  
#Initialize the vector
    x
    = 3
  
#prints the new vector
      puts vec1
      * x

输出

Vector[3, 6]

示例 2

#Ruby program for* method in Vector
  
#Include matrix
require "matrix"
  
#Initialize the vector
    vec1
    = Vector[1, 2, 3]
  
#Initialize the vector
    x
    = 3
  
#prints the new vector
      puts vec1
      * x

输出

Vector[3, 6, 9]