用余弦定律计算向量(Python)

2024-03-28 19:00:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着开发一个控制台应用程序,用余弦定律解决向量之间的加法:

sum = sqrt((s1 ** 2) + (s2 ** 2) + (2 * s1 * s2 * cos(angle)))
print(sum)

# Where s1 and s2 are the sizes of the vectors, respectively.

但是,等式中的cos返回了一个奇怪的值(角度是60,所以cos(angle)应该是1/2,对吧?)。你知道吗

另外,在阅读其他解决方案后,我尝试用acos更改cos,但它返回ValueError: math domain error。你知道吗

有人知道怎么解决这个问题吗?你知道吗


Tags: andthe应用程序sqrtcoswhere向量are