我试过了norm,但我认为它给出了错误的结果.(规范c(1, 2, 3)是sqrt(1*1+2*2+3*3),但它返回6..
x1 <- 1:3
norm(x1)
# Error in norm(x1) : 'A' must be a numeric matrix
norm(as.matrix(x1))
# [1] 6
as.matrix(x1)
# [,1]
# [1,] 1
# [2,] 2
# [3,] 3
norm(as.matrix(x1))
# [1] 6
Run Code Online (Sandbox Code Playgroud)
有谁知道在R中计算向量范数的函数是什么?
我究竟做错了什么?
> crossprod(1:3,4:6)
[,1]
[1,] 32
Run Code Online (Sandbox Code Playgroud)
根据这个网站:http://onlinemschool.com/math/assistance/vector/multiply1/
它应该给:
{-3; 6; -3}
Run Code Online (Sandbox Code Playgroud)
另请参阅什么是R的交叉产物功能?