问题调用math.cos() [英] Problem calling math.cos()

查看:88
本文介绍了问题调用math.cos()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模块:

-------------------------------

导入数学

def ac_add_a_ph(amp1,ph1,amp2,ph2):


amp3 = 0.0
ph3 = 0.0

ac1 =(0,0j)

ac2 =(0,0j)

ac3 =(0 ,0j)

ac1 =复数(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(math.radians(ph1)))

ac2 =复数(amp2 * math.cos(math.radians(ph2)),amp2 * math.sin(math.radians(ph2)))

ac3 = ac1 + ac2

amp3 = math.abs(ac3)

ph3 = math.atan(ac3.imag / ac3.real)

return [amp3,ph3]

--------------------------------------

当我在windows2000中的python.exe中导入它(电子产品)和

尝试使用它时,它呱呱叫。 ???

I have the following module:
-------------------------------
import math

def ac_add_a_ph( amp1, ph1, amp2, ph2 ):

amp3 = 0.0
ph3 = 0.0
ac1 = ( 0, 0j )
ac2 = ( 0, 0j )
ac3 = ( 0, 0j )
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin( math.radians( ph1 ) ) )
ac2 = complex( amp2 * math.cos( math.radians( ph2 ) ), amp2 * math.sin( math.radians( ph2 ) ) )
ac3 = ac1 + ac2
amp3 = math.abs( ac3 )
ph3 = math.atan( ac3.imag / ac3.real )
return [amp3, ph3]
--------------------------------------
when I import it (electronics) in python.exe in windows2000 and
try to use it, it croaks. ???

import math
import electronics
print electronics.ac_add_a_ph(10, 0,6,45)
回溯(最近一次调用最后一次):

文件"< stdin>",第1行,在?

文件f:\devel \ python \ electrononics.py,第10行,在ac_add_a_ph

ac1 = complex(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(math

..radians(ph1)))

NameError:全局名称''cos''未定义
import math
import electronics
print electronics.ac_add_a_ph( 10, 0 , 6 , 45 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "f:\devel\python\electronics.py", line 10, in ac_add_a_ph
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin( math
..radians( ph1 ) ) )
NameError: global name ''cos'' is not defined



全球?嗯?

abs代表什么?为什么那不是绝对的价值?嗯。

嗯,复杂的数字,很酷我甚至不知道C

在哪里站着。


global?? huh?
what does abs stand for? why is that not absolute value? hmmm.
Hmm, complex numbers, cool I don''t even have any idea where C
stands on this.

推荐答案

在文章< 3e ***************** @ newsfe15.lga>中,Sambo< sa *** @ void.com>

写道:
In article <3e*****************@newsfe15.lga>, Sambo <sa***@void.com>
wrote:
我有以下模块:
-------------- -----------------
导入数学

def ac_add_a_ph(amp1,ph1,amp2,ph2):
amp3 = 0.0
ph3 = 0.0
ac1 =(0,0j)
ac2 =(0,0j)
ac3 =(0,0j)
ac1 =复数(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(
math.radians(ph1)))
ac2 = complex(amp2 * math.cos(math。弧度(ph2)),amp2 * math.sin(
math.radians(ph2)))
ac3 = ac1 + ac2
amp3 = math.abs(ac3)
ph3 = math.atan(ac3.imag / ac3.real)
返回[amp3,ph3]
----------------------- ---------------
我在windows2000中的python.exe中导入它(电子产品)并尝试使用它,它呱呱叫。 ???
I have the following module:
-------------------------------
import math

def ac_add_a_ph( amp1, ph1, amp2, ph2 ):

amp3 = 0.0
ph3 = 0.0
ac1 = ( 0, 0j )
ac2 = ( 0, 0j )
ac3 = ( 0, 0j )
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin(
math.radians( ph1 ) ) )
ac2 = complex( amp2 * math.cos( math.radians( ph2 ) ), amp2 * math.sin(
math.radians( ph2 ) ) )
ac3 = ac1 + ac2
amp3 = math.abs( ac3 )
ph3 = math.atan( ac3.imag / ac3.real )
return [amp3, ph3]
--------------------------------------
when I import it (electronics) in python.exe in windows2000 and
try to use it, it croaks. ???
import math
import electronics
print electronics.ac_add_a_ph(10,0,6,45)Traceback(最近的呼叫最后一次):
文件"< stdin>",第1行,在文件f:\devel \ python \ electrononics.py中,第10行,在ac_add_a_ph
ac1 =复杂(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(
数学
。radians(ph1)))
NameError:全局名称''cos''未定义


这不是我运行时获得的(不可否认,不是在Windows上)。我得到:

导入数学
导入电子产品
print electronics.ac_add_a_ph(10,0,6,45)
Traceback(最近一次调用最后一次):

文件"< stdin>",第1行,在?

文件" electronics.py",第13行,在ac_add_a_ph

amp3 = math.abs(ac3)

AttributeError:''module''对象没有属性''abs''
import math
import electronics
print electronics.ac_add_a_ph( 10, 0 , 6 , 45 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "f:\devel\python\electronics.py", line 10, in ac_add_a_ph
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin(
math
.radians( ph1 ) ) )
NameError: global name ''cos'' is not defined
That''s not what I get when I run it (admittedly, not on windows). I get:
import math
import electronics
print electronics.ac_add_a_ph( 10, 0 , 6 , 45 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "electronics.py", line 13, in ac_add_a_ph
amp3 = math.abs( ac3 )
AttributeError: ''module'' object has no attribute ''abs''




这正是我的预期,因为abs(确实绝对值是b $ b值)是一个内置函数,而不是数学模块的一部分。你确定

你发布的堆栈跟踪与你发布的源代码匹配吗?


顺便说一下,当使用数学函数时,我发现它是'通过从数学导入*进入,通常更容易导入

它们进入我的命名空间,然后我可以直接使用

sin(),cos()等等而不是必须做math.sin()或

math.cos()。特别是对于常见的数学函数,这使得你的代码更容易阅读。



which is exactly what I expected, since abs (which is indeed absolute
value) is a built-in function, not a part of the math module. Are you sure
the stack trace you posted matches the source code you posted?

By the way, when using math functions, I find it''s usually easier to import
them into my namespace by doing "from math import *", then I can just use
sin(), cos(), etc directly, instead of having to do math.sin() or
math.cos(). Especially for common math functions, this makes your code a
lot easier to read.


Sambo< sa *** @ void.com> ;写道:
Sambo <sa***@void.com> wrote:
我有以下模块:
-------------------------- -----
导入数学

def ac_add_a_ph(amp1,ph1,amp2,ph2):

amp3 = 0.0
ph3 = 0.0
ac1 =(0,0j)
ac2 =(0,0j)
ac3 =(0,0j)


你在定义ac1 ,ac2,ac3作为元组,每个都有两个项目。这是傻瓜:删除这三个无用且令人困惑的线路(前两个是b $ $ $ $ $ $ $ $ $ $ $ $))))))))))))))没有损坏,但是,可以避免额外的混淆。

ac1 =复杂(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(math.radians(ph1)))ac2 =复数(amp2 * math.cos(math.radians(ph2)),amp2 * math.sin(math.radians(ph2)))ac3 = ac1 + ac2
amp3 = math.abs(ac3)
ph3 = math.atan(ac3.imag / ac3.real)
返回[amp3,ph3]
-------------------- ------------------
当我在windows2000中的python.exe中导入它(电子产品)时,尝试使用它,它会呱呱叫。 ???
I have the following module:
-------------------------------
import math

def ac_add_a_ph( amp1, ph1, amp2, ph2 ):

amp3 = 0.0
ph3 = 0.0
ac1 = ( 0, 0j )
ac2 = ( 0, 0j )
ac3 = ( 0, 0j )
You''re defining ac1, ac2, ac3 as tuples, each with two items. That''s
silly: remove these three useless and confusing lines (the first two are
prety silly too). No damage, but, avoidable extra confusion.
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin( math.radians( ph1 ) ) ) ac2 = complex( amp2 * math.cos( math.radians( ph2 ) ), amp2 * math.sin( math.radians( ph2 ) ) ) ac3 = ac1 + ac2
amp3 = math.abs( ac3 )
ph3 = math.atan( ac3.imag / ac3.real )
return [amp3, ph3]
--------------------------------------
when I import it (electronics) in python.exe in windows2000 and
try to use it, it croaks. ???
import math
import electronics
print electronics.ac_add_a_ph(10,0,6,45)Traceback(最近的呼叫最后一次):
文件"< stdin>",第1行,在文件f:\devel \ python \ electrononics.py中,第10行,在ac_add_a_ph
ac1 =复杂(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(数学.radians(ph1)))


[[某些行拆分为尊重NNTP对80-char行的约束]]

NameError:全局名称''cos''未定义
import math
import electronics
print electronics.ac_add_a_ph( 10, 0 , 6 , 45 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "f:\devel\python\electronics.py", line 10, in ac_add_a_ph
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin( math .radians( ph1 ) ) )
[[some lines split to respect NNTP''s constraint on 80-char lines]]
NameError: global name ''cos'' is not defined


全球?嗯?




很奇怪 - 我无法重现这个;例如,当你错误地使用逗号而不是点时,这是你得到的那种症状,但是我没有看到

你的错误代码。


我看到的是AttributeError:''模块''对象没有属性

''abs''"关于amp3任务 - 当然,因为那确实是

的事实(绝对是内置的,不是模块数学的成员)。


最有可能的是,你有点困惑,并没有完全复制粘贴

发生了什么。


abs代表什么?为什么那不是绝对的价值?嗯。


abs代表绝对价值。

嗯,复杂数字,很酷我甚至不知道C
站在哪里在这个。



Weird -- I can''t reproduce this; it''s the kind of symptom you get when
mistakenly using a comma instead of a dot, for example, but I don''t see
that error in your code.

What I _do_ see is an "AttributeError: ''module'' object has no attribute
''abs''" on the amp3 assignment -- of course, because that''s indeed the
fact (abs is a builtin, not a member to module math).

Most likely, you got a bit confused and didn''t copy-and-paste exactly
what was going on.

what does abs stand for? why is that not absolute value? hmmm.
abs does stand for absolute-value.
Hmm, complex numbers, cool I don''t even have any idea where C
stands on this.




C对复数没有立场。

Alex



C has no stand on complex numbers.
Alex


Sambo写道:
我有以下模块:
---------------------------- ---
导入数学

def ac_add_a_ph(amp1,ph1,amp2,ph2):

amp3 = 0.0
ph3 = 0.0 ac1 =(0,0j)
ac2 =(0,0j)
ac3 =(0,0j)
ac1 = complex(amp1 * math.cos(math.radians(ph1) ),amp1 * math.sin(math.radians(ph1)))
ac2 = complex(amp2 * math.cos(math.radians(ph2)),amp2 * math.sin(math.radians(ph2) ))
ac3 = ac1 + ac2
amp3 = math.abs(ac3)
ph3 = math.atan(ac3.imag / ac3.real)
返回[amp3,ph3 ]
--------------------------------------
我导入的时候它(elec tronics)在windows2000中的python.exe和
尝试使用它,它呱呱叫。 ???
I have the following module:
-------------------------------
import math

def ac_add_a_ph( amp1, ph1, amp2, ph2 ):

amp3 = 0.0
ph3 = 0.0
ac1 = ( 0, 0j )
ac2 = ( 0, 0j )
ac3 = ( 0, 0j )
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin( math.radians( ph1 ) ) )
ac2 = complex( amp2 * math.cos( math.radians( ph2 ) ), amp2 * math.sin( math.radians( ph2 ) ) )
ac3 = ac1 + ac2
amp3 = math.abs( ac3 )
ph3 = math.atan( ac3.imag / ac3.real )
return [amp3, ph3]
--------------------------------------
when I import it (electronics) in python.exe in windows2000 and
try to use it, it croaks. ???
import math
导入电子产品
print electronics.ac_add_a_ph(10,0,6,45)文件"< stdin>",第1行,在?
文件" f:\ devel \ python \ electrononics.py" ,第10行,在ac_add_a_ph
ac1 =复杂(amp1 * math.cos(math.radians(ph1)),amp1 * math.sin(math
。radians(ph1)))
NameError:全局名称''cos''未定义

全局?是吧?


这不是我得到的。


[〜]
import math
import electronics
print electronics.ac_add_a_ph( 10, 0 , 6 , 45 )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "f:\devel\python\electronics.py", line 10, in ac_add_a_ph
ac1 = complex( amp1 * math.cos( math.radians( ph1 ) ), amp1 * math.sin( math
.radians( ph1 ) ) )
NameError: global name ''cos'' is not defined

global?? huh?
That''s not what I get.

[~]


这篇关于问题调用math.cos()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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