与余弦定律 SAS 作斗争
Struggling with Law of Cosines SAS
在我的数学 class 中,我们在三角学单元中学习 Sines/Law 余弦定律。我编写的程序从数学问题中获取已知值,并在我无聊时吐出答案。
我正在努力编写一个算法来解决 Side/Angle/Side (SAS) 问题。我正在使用这个问题作为参考(为质量道歉):
在纸上计算时,大约等于 10.7 个单位。
到目前为止,这是我的代码:
import math
# Law of Cosines
# SAS
print("Cosines: SAS")
x = float(input("Known Side Length #1: "))
y = float(input("Known Side Length #2: "))
z = float(input("Known Angle Degrees: "))
a = ((x*x)+(y*y))-(2*x*y*math.radians(math.cos(z)))
b = math.sqrt(a)
print(str(b))
这里是使用代码时的结果:
Cosines: SAS
Known Side Length #1: 5
Known Side Length #2: 9
Known Angle Degrees: 95
10.23977763686627
显然,这些答案并不相同。我将 a
和 b
分开来尝试找出问题出在哪里,它似乎在 a
中,因为它给出的值不等于纸上的 c^2 (我之前也在打印 a
的值)。
是代码错了,还是我纸上写错了?如果代码有误,欢迎提供帮助。
别管大家,我傻了。我把 math.cos
和 math.radians
颠倒了。感谢您查看!
新代码:
print("Cosines: SAS")
x = float(input("Known Side Length #1: "))
y = float(input("Known Side Length #2: "))
z = float(input("Known Angle Degrees: "))
a = ((x*x)+(y*y))-(2*x*y*math.cos(math.radians(z)))
b = math.sqrt(a)
print(str(b))
在我的数学 class 中,我们在三角学单元中学习 Sines/Law 余弦定律。我编写的程序从数学问题中获取已知值,并在我无聊时吐出答案。
我正在努力编写一个算法来解决 Side/Angle/Side (SAS) 问题。我正在使用这个问题作为参考(为质量道歉):
在纸上计算时,大约等于 10.7 个单位。
到目前为止,这是我的代码:
import math
# Law of Cosines
# SAS
print("Cosines: SAS")
x = float(input("Known Side Length #1: "))
y = float(input("Known Side Length #2: "))
z = float(input("Known Angle Degrees: "))
a = ((x*x)+(y*y))-(2*x*y*math.radians(math.cos(z)))
b = math.sqrt(a)
print(str(b))
这里是使用代码时的结果:
Cosines: SAS
Known Side Length #1: 5
Known Side Length #2: 9
Known Angle Degrees: 95
10.23977763686627
显然,这些答案并不相同。我将 a
和 b
分开来尝试找出问题出在哪里,它似乎在 a
中,因为它给出的值不等于纸上的 c^2 (我之前也在打印 a
的值)。
是代码错了,还是我纸上写错了?如果代码有误,欢迎提供帮助。
别管大家,我傻了。我把 math.cos
和 math.radians
颠倒了。感谢您查看!
新代码:
print("Cosines: SAS")
x = float(input("Known Side Length #1: "))
y = float(input("Known Side Length #2: "))
z = float(input("Known Angle Degrees: "))
a = ((x*x)+(y*y))-(2*x*y*math.cos(math.radians(z)))
b = math.sqrt(a)
print(str(b))