结果不正确的数学异常? [英] Unusual Math with incorrect results?

查看:110
本文介绍了结果不正确的数学异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用math.cos()和math.sin()函数时,我的python解释器表现得很时髦.例如,如果我在计算器上执行此操作:

My python interpreter is acting funky when I use the math.cos() and math.sin() function. For example, if I do this on my calculator:

cos(35)*15+9 = 21.28728066
sin(35)*15+9 = 17.60364655

但是当我在python(3.2和2.7)上执行此操作

But when I do this on python (both 3.2 and 2.7)

>>> import math
>>> math.cos(35)*15+9
-4.5553830763726015

>>> import math
>>> math.sin(35)*15+9
2.577259957557734

为什么会这样?

为了以防万一,如何将Python中的弧度更改为度?

How do you change the Radian in Python to degrees, just in case?

推荐答案

这是由于您使用学位
并且三角函数期望 radians 作为输入:
sin(radians)

This is being caused by the fact that you are using degrees
and the trigonometric functions expect radians as input:
sin(radians)

sin的描述为:

sin(x)
    Return the sine of x (measured in radians).

在Python中,您可以使用math.radians函数将度数转换为弧度.

In Python, you can convert degrees to radians with the math.radians function.


因此,如果您使用输入来执行此操作:


So if you do this with your input:

>>> math.sin(math.radians(35)) * 15 + 9
17.60364654526569

其结果与您的计算器相同.

it gives the same result as your calculator.

这篇关于结果不正确的数学异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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