how to calculate the Euclidean norm of a vector in R?

后端 未结 10 1095
灰色年华
灰色年华 2021-02-01 13:22

I tried norm, but I think it gives the wrong result. (the norm of c(1, 2, 3) is sqrt(1*1+2*2+3*3), but it returns 6..

10条回答
  •  心在旅途
    2021-02-01 14:04

    We can also find the norm as :

    Result<-sum(abs(x)^2)^(1/2)
    

    OR Even You can also try as:

    Result<-sqrt(t(x)%*%x)
    

    Both will give the same answer

提交回复
热议问题