R中两个向量之间的角度 [英] Angle between two vectors in R

查看:507
本文介绍了R中两个向量之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编程语言中最有效的方法是计算两个向量之间的角度? R ?根据 Math6397 / day13 / LinearAlgebraR-Handout.pdfrel =noreferrer>本PDF sum(a * b)是找到点的R命令向量的乘积 a b sqrt(sum(a * a))是用于查找向量 a 的准则的R命令,并且 acos(x)是用于弧余弦的R命令。因此,用于计算两个矢量之间角度的R码是

  theta <-acos(sum(a * b )/(sqrt(sum(a * a))* sqrt(sum(b * b))))


What the most efficient way in the programming language R to calculate the angle between two vectors?

解决方案

According to page 5 of this PDF, sum(a*b) is the R command to find the dot product of vectors a and b, and sqrt(sum(a * a)) is the R command to find the norm of vector a, and acos(x) is the R command for the arc-cosine. It follows that the R code to calculate the angle between the two vectors is

theta <- acos( sum(a*b) / ( sqrt(sum(a * a)) * sqrt(sum(b * b)) ) )

这篇关于R中两个向量之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆