数学模块坏了? [英] math module broken?

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

问题描述

大家好


我昨晚用她的三角学作业帮助了我的侄女。她的b $ b计算器的电池电量不足,所以我想我会用Python的

数学模块来计算sin,cos和tan。


我首先在教科书中尝试了这个例子,以确保我得到了正确的结果,但是它不同意。然后我的妻子有了在科学模式下使用微软计算器的想法,并且

确实给出了正确的结果。


以下是一些例子 -


sin(32) -

Python 0.55142668

Microsoft 0.52991926


cos(32) -

Python 0.83422336

Microsoft 0.84804809


tan(32) -

Python 0.66100604

Microsoft 0.62486935


Windows 2000上获得相同的结果。我也使用cmath模块获得相同的结果。


有人可以解释这些差异吗?


谢谢


Frank Millman

Hi all

I was helping my niece with her trigonometry homework last night. Her
calculator''s batteries were flat, so I thought I would use Python''s
math module to calculate sin, cos, and tan.

I tried the example in the text book first, to ensure that I was
getting the correct result, but it did not agree. Then my wife had the
idea of using the Microsoft calculator in scientific mode, and that
one did give the correct result.

Here are some examples -

sin(32) -
Python 0.55142668
Microsoft 0.52991926

cos(32) -
Python 0.83422336
Microsoft 0.84804809

tan(32) -
Python 0.66100604
Microsoft 0.62486935

Version is Python 2.3.3. I get the same results on Linux and on
Windows 2000. I also get the same results using the cmath module.

Can someone please explain these discrepancies?

Thanks

Frank Millman

推荐答案

fr *** @ chagford.com (Frank Millman)写道:
fr***@chagford.com (Frank Millman) writes:
sin(32) -
Python 0.55142668
Microsoft 0.52991926


Python的数字是32弧度的罪,这与0.584弧度的sin

相同。微软是32度的罪,这是0.558

弧度,所以结果恰好相当接近一个

另一个。数学库通常采用弧度args而

计算器通常允许你在弧度和度数之间进行选择。

cos(32) -
Python 0.83422336
微软0.84804809

tan(32) -
Python 0.66100604
Microsoft 0.62486935
sin(32) -
Python 0.55142668
Microsoft 0.52991926
Python''s number is the sin of 32 radians which is the same as the sin
of 0.584 radians. Microsoft''s is the sin of 32 degrees which is 0.558
radians, so the results are coincidentally fairly close to one
another. Math libraries usually take args in radians while
calculators usually let you select between radians and degrees.
cos(32) -
Python 0.83422336
Microsoft 0.84804809

tan(32) -
Python 0.66100604
Microsoft 0.62486935




同样的事情。



Same thing.


Frank Millman写道:
Frank Millman wrote:
大家好

我昨晚用她的三角学作业帮我的侄女。她的计算器电池电量不足,所以我想我会用Python的数学模块计算sin,cos和tan。

我试过这个例子在第一本教科书中,为了确保我得到了正确的结果,但它并不同意。然后我的妻子有了在科学模式下使用微软计算器的想法,并且确实给出了正确的结果。

以下是一些例子 -

sin(32) -
Python 0.55142668
Microsoft 0.52991926

版本是Python 2.3.3。我在Linux和Windows 2000上得到了相同的结果。我也使用cmath模块获得相同的结果。

有人可以解释这些差异吗?
Hi all

I was helping my niece with her trigonometry homework last night. Her
calculator''s batteries were flat, so I thought I would use Python''s
math module to calculate sin, cos, and tan.

I tried the example in the text book first, to ensure that I was
getting the correct result, but it did not agree. Then my wife had the
idea of using the Microsoft calculator in scientific mode, and that
one did give the correct result.

Here are some examples -

sin(32) -
Python 0.55142668
Microsoft 0.52991926
Version is Python 2.3.3. I get the same results on Linux and on
Windows 2000. I also get the same results using the cmath module.

Can someone please explain these discrepancies?




两者都是正确的如果你知道你一直在要求什么。

在标准数学中,三角函数的参数如

sin,cos,tan,...是弧度(!) )

大多数袖珍计算器都是如此,但你可以切换

模式。

在上面的例子中,微软 - 特别的东西一如既往 - 似乎期望

以度为单位的论点(这是非常不寻常的)


因为弧度中的参数通常在0到2 * pi之间或者在-pi和pi之间,

参数32对于弧度论证是不寻常的,虽然完全合法。


如果你的输入是度数,定义


def mysin(x)

返回math.sin(x / pi * 180)#1度= 180 / pi弧度(不要使用x / 180 * pi)


现在

打印mysin(32)给出0.529919264233

-

Helmut Jarausch


Lehrstuhl fuer Numerische Mathematik

RWTH - 亚琛大学

D 52056德国亚琛



Both are "correct" if you know what you have been asking for.
In standard mathematics the argument to a trigonometric function like
sin, cos, tan, ... is in radians (!)
This is even the case with most pocket calculators but there you can switch
modes.
In the example above, Microsoft - something special as ever - seems to expect
the argument in degrees (which is quite unusual)

Since an argument in radians normally is between 0 and 2*pi or between -pi and pi,
an argument of 32 is unusual for a radians argument though perfectly legal.

If your input is in degrees, define

def mysin(x)
return math.sin(x/pi*180) # 1 degree = 180/pi radians (don''s use x/180*pi)

now
print mysin(32) gives 0.529919264233
--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany


Helmut Jarausch< ja ****** @ igpm.rwth-aachen.de>在消息中写道
Helmut Jarausch <ja******@igpm.rwth-aachen.de> wrote in message
两者都是正确的如果你知道你一直在要求什么。
在标准数学中,三角函数的参数如
sin,cos,tan,...是弧度(!)


最近在

comp.lang.fortran中讨论过这个问题,当有人查询罪/ cos / tan等时出现

非常大的角度(以浮点表示,例如:sin(1.0E18))。

如果使用

* rational *单位进行测量,则减少(角度模2pi)会相当容易角度,因为答案可以保持准确

,以浮点表示的特定数字。

不使用无理数,精确表示角度

实际上可以存在于你也有正确的正弦表示

和余弦。使用弧度,你只能准确地表示零,并且低于它的
似乎不是那样的!


有人可以提供一个真实的具体例子,其中有理由

在计算sin / cos / tan时更喜欢弧度? (不是他们的衍生品!)


三个例子中最后一个是最令人失望的:


C:\> python

Python 2.3.3(#51,2003年12月18日,20:22:39)[MSC v.1200 32位(英特尔)]
win32上


输入help,copyright,credit等。或许可证或更多信息。
Both are "correct" if you know what you have been asking for.
In standard mathematics the argument to a trigonometric function like
sin, cos, tan, ... is in radians (!)
There was some discussion about this recently over in
comp.lang.fortran, arising when someone queried sin/cos/tan etc for
very large angles (represented in floating point, eg: sin(1.0E18)).
Reduction (angle modulo 2pi) is considerably easier if you use a
*rational* unit for measuring angles, as the answer can remain exact
in terms of the particular number represented in floating point.
Without using an irrational number, exact representations of angles
can actually exist where you also have exact representations of sines
and cosines. With radians you can only represent zero exactly, and
below it seems not even that!

Can someone supply a real concrete example where there is a reason to
prefer radians when computing sin/cos/tan? (Not their derivatives!)

The latter of the three examples is most disappointing:

C:\>python
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
来自math import sin,asin,pi
sin(pi / 6)#== 0.5
0.49999999999999994度(asin(0.5))#== 30
30.000000000000004 sin(pi)#== 0
from math import sin,asin,pi
sin(pi/6) # == 0.5 0.49999999999999994 degrees(asin(0.5)) # == 30 30.000000000000004 sin(pi) # == 0



1.2246063538223773 e-016


使用圆的一些有理分数代表角度所有这些

废话消失了。为什么要转换为一个消除了任何结果的确切表示的可能性的单位?

在上面的例子中,微软 - 一如既往的特殊 - 似乎期待
以度为单位的论证(这很不寻常)


1.2246063538223773e-016

I understand why this fails - I just think the world is wrong.
Represent angles using some rational fraction of a circle and all this
crap goes away. Why convert to a unit which eliminates the possibility
of an exact representation of any result at all?
In the example above, Microsoft - something special as ever - seems to expect
the argument in degrees (which is quite unusual)




微软计算器有一个复选框,用于在度数之间切换

和弧度并获得上述所有分析结果。我们

生活在一个疯狂的世界......


Jon



The microsoft calculator has a checkbox for switching between degrees
and radians and gets all of the analytical results above correct. We
live in a mad world....

Jon


这篇关于数学模块坏了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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