Jump to content

math and cmath

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
xzwerm

xzwerm

    Newbie

  • Members
  • Pip
  • 7 posts
I have just started in python and I am reading
9.3. cmath ? Mathematical functions for complex numbers — Python v2.7 documentation
what is the difference between these and the sum([]) function

I can use sum([4.5, 5.5]) to return the sum but the other ones return an error
NameError: name 'tan' is not defined

what do i have to do to use all these math functions?

and what is the difference between math and cmath?

#2
Hignar

Hignar

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 420 posts
Complex numbers are a fairly advanced mathematical concept and chances are you won't have encountered them if you haven't done any advanced maths courses. I don't think I really got to grips with them until university but I may have studied them at school as well.

Basically a complex number is made up of two parts, the real and the imaginary. The real part is just like any 'normal' number while the complex number is expressed as a multiple of i, where i is the square root of -1.

If you are struggling to follow the documentation for cmath I would recommend one of two things

1. Read up on complex numbers. It's an incredibly rich topic but the basics should be enough for now.

2. Leave the cmath module for now. If you don't understand complex numbers chances are that you won't ever want or need to use the module.
If there's a new way, I'll be the first in line.

But, it better work this time.

#3
xzwerm

xzwerm

    Newbie

  • Members
  • Pip
  • 7 posts
so are math and cmath only used with complex numbers? I just thought i could use the python interpreter to solve trigonometric and other math problems.

#4
Hignar

Hignar

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 420 posts
Only cmath is used for complex numbers. For regular use the math module should he fine.
If there's a new way, I'll be the first in line.

But, it better work this time.