Re: [Tutor] Complex roots

2004-12-16 Thread Dick Moores
Thanks. Tim Peters helped me out with his answer of 12/9. Dick Moores Jacob S. wrote at 19:27 12/15/2004: Finding the all the roots of a complex number shouldn't be too difficult. I tend to do it on paper sometimes. Maybe I can wr

Re: [Tutor] Complex roots

2004-12-16 Thread Jacob S.
Finding the all the roots of a complex number shouldn't be too difficult. I tend to do it on paper sometimes. Maybe I can write a script to do it for me instead. I stongly caution you though. The methods that I show below are unstable and should be verified by a math web site as it has been quite

Re: [Tutor] Complex roots

2004-12-15 Thread Dick Moores
Alan Gauld wrote at 09:25 12/12/2004: > Are these "numerical approximation methods" pythonically possible? > Yes and that's how they are normally found - not necessarily with Python, but by applying computer simulations of the equations. Generally you calculate values in ever decreasing increments

Re: [Tutor] Complex roots

2004-12-12 Thread Dick Moores
Hmm, sounds like something to sink my teeth into for a while. Thanks for just enough of a hint as to how to go about it. But on second thought, how about another hint. How are imaginary roots approximated? For each root, do you try to approximate root.real and root.imag simultaneously, or what?

Re: [Tutor] Complex roots

2004-12-12 Thread Tim Peters
[Dick Moores] >>> Actually, I'm trying to write a Python script that computes all 3 >>> roots of a cubic equation. Do you happen to have one tucked >>> away in your store of wisdom and tricks? (One for real coefficients >>> will do). [Tim Peters] >> I don't, no. You can code one for cubics from C

Re: [Tutor] Complex roots

2004-12-12 Thread Dick Moores
Thanks for the sobering advice, and for the two sites I knew nothing about. So there's a SciPy! Dick Tim Peters wrote at 20:37 12/12/2004: > Are these "numerical approximation methods" pythonically possible? Of course, but coding general-purpose root finders-- even if "general" is limited to just

Re: [Tutor] Complex roots

2004-12-12 Thread Alan Gauld
> Are these "numerical approximation methods" pythonically possible? > Yes and that's how they are normally found - not necessarily with Python, but by applying computer simulations of the equations. Generally you calculate values in ever decreasing increments until you get enough accuracy. eg you

Re: [Tutor] Complex roots

2004-12-12 Thread Dick Moores
Tim (was: Bill) Peters wrote at 20:45 12/10/2004: [Dick Moores] > Aw, that's just amazing. > I put your function in http://www.rcblue.com/Python/croots.py, That's fine by me -- but I'd appreciate it if you stopped claiming there that my name is Bill . Are you sure? Well, OK. Tim it is. > Actually

Re: [Tutor] Complex roots

2004-12-10 Thread Tim Peters
[Dick Moores] > Aw, that's just amazing. Well, complex numbers are amazing in many ways. The code is actually obvious, if you understand the motivation. Polar coordinates are more natural for complex * / and **. If you a view a complex number c as a vector in the complex plane (from the origin

Re: [Tutor] Complex roots

2004-12-10 Thread Dick Moores
Oops. Make that croots3.py (). I forgot a couple of abs's. For example, "if n.imag < 1e-13:" is changed to "if abs(n.imag) < 1e-13:" Dick Dick Moores wrote at 07:38 12/10/2004: I've modified croots.py to croots2.py (

Re: [Tutor] Complex roots

2004-12-10 Thread Dick Moores
I've modified croots.py to croots2.py () The only changes are in the testCrootsResult function. It will ignore very small .imag or .real when printing. Thus this result: Enter either a complex number in form x + yj, or a

Re: [Tutor] Complex roots

2004-12-10 Thread Dick Moores
Aw, that's just amazing. I put your function in http://www.rcblue.com/Python/croots.py, which gets c and n from user and adds a test function. Here's what one run produces: Enter either a complex number in form x + yj, or a real number: 3.1 -1j Enter an intege

Re: [Tutor] Complex roots

2004-12-09 Thread Tim Peters
[Dick Moores] > VERY helpful, Matt. Thanks. > > One question: This seems to not compute accurately at all > when the imaginary part of number=complex() is other than 0. That's just because the math was wrong . Starting with theta = 0.0 *assumed* the imaginary part is 0, although I can't guess wh

Re: [Tutor] Complex roots

2004-12-09 Thread Dick Moores
VERY helpful, Matt. Thanks. One question: This seems to not compute accurately at all when the imaginary part of number=complex() is other than 0. For example, number=complex(5,5): With number=complex(5,5) n=float(4) the code produces {0: (1.631, 0.0), 1: (0.0, 1.631), 2: (-1.631, 0.0), 3: (0.0