Re: Problem calling math.cos()



Sambo <sambo@xxxxxxxx> wrote:

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 (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



global?? huh?

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 has no stand on complex numbers.


Alex
.



Relevant Pages

  • Re: Problem calling math.cos()
    ... import math ... import electronics ... Change math.abs() to abs. ... "I have come to believe that the whole world is an enigma, a harmless enigma ...
    (comp.lang.python)
  • Re: A Modest Proposal
    ... Saying "I find such and such confusing", ... come to a vote in the math community as to which was more sensible, ... Your main evidence is your ludicrous sarcasm ...
    (sci.logic)
  • Re: A Modest Proposal
    ... I find that statement very confusing. ... math and classical math is merely one of terminology. ... a classical mathematician says Y". ... But this is a matter of "mere constructivism", ...
    (sci.logic)
  • Re: Light speed invariance
    ... confusing language people sometimes say ... This topic on the sqrtfunction has *nothing* to do with physics. ... This is pure math. ... That's what would-be religious fanatics like you need: priests for ...
    (sci.physics.relativity)
  • Re: WSEX rake is credited
    ... still be in the "poker account" Their details are confusing ... but the math works out. ... "The way of the samurai is found in death. ...
    (rec.gambling.poker)