将浮点数和向量相乘?那么val scale:float-> float * float-> float * float?

时间:2018-09-30 17:41:09

标签: f#

我如何制作一个函数scale(),将浮点数和向量相乘。它必须使用这里显示的这个库吗?我认为这叫做库,如果那是错的,抱歉。

/// Multiplication of a float and a vector
val scale : float -> float * float -> float * float

花了4个小时试图弄清楚。

我的任务(数据科学第3周)是,我有一个包含2D矢量库的签名文件,我需要使用该库来制作函数。

/// A 2D vector library

/// Vectors are represented as pairs of floats module vec2d

/// The length of a vector
val len : float * float -> float
/// The angle of a vector
val ang : float * float -> float
/// Multiplication of a float and a vector
val scale : float -> float * float -> float * float
/// Addition of two vectors
val add : float * float -> float * float -> float * float
/// Dot product of two vectors
val dot : float * float -> float * float -> float

目前,我有:

// LENGTH OF A VECTOR
// val len : float * float -> float
let len (x: float, y: float) =
    sqrt(x**2.0 + y**2.0)

// ANGLE OF A VECTOR
// val ang : float * float -> float
let ang (x: float, y: float) =
    Math.Atan2(y, x)

// MULTIPLICATION OF A FLOAT AND A VECTOR
// val scale : float -> float * float -> float * float
let scale () =
    None

/// ADDITION OF TWO VECTORS
// add : float * float -> float * float -> float * float 
let add (xy1: float, xy2: float) =
    None 

/// DOT PRODUCT OF TWO VECTORS
// dot : float * float -> float * float -> float
let dot (xy1: float, xy2: float) =
    None

enter image description here

任何一种帮助/提示都将非常有帮助!我被卡住了!

1 个答案:

答案 0 :(得分:1)

这是您要找的吗?

let scale n (x: float, y: float) =
    n*x, n*y

这会将向量元组(x,y)中的每个值乘以浮点n。