Re: [Tutor] Little problem with math module

2008-05-21 Thread Terry Carroll
On Wed, 21 May 2008, Terry Carroll wrote: > The following (barely-tested) routine should calculate all the Nth roots > of a given x, even when x is negative and N is even: I realize I'm probably talking to myself here, but for the benefit of the archives, I found a more elegant approach after re

Re: [Tutor] Little problem with math module

2008-05-21 Thread Terry Carroll
> "Tiago Katcipis" <[EMAIL PROTECTED]> wrote > > > def newton_divergente(x): > > return math.pow(x, 1.0/3.0) > > > > but when x = -20 it returns this error > > > > return math.pow(x, 1.0/3.0) > > ValueError: math domain error > > > > but why is that? is it impossible to calculate -20 ^ (1/3)

Re: [Tutor] Little problem with math module

2008-04-22 Thread Andreas Kostyrka
Hmmm, the power function has basically two definitions: a ** n for integer n, pow is defined for all a in R. for real n, pow is defined only for non-negative a. If you think how a**x is derived (as a generalization from a**(p/q)), that makes sense. Basically, a ** (p/q), p > 0, q > 0, gcd(p, q)

Re: [Tutor] Little problem with math module

2008-04-21 Thread tiger12506
ing global erro and then using modulename.erro when he uses the actual value. - Original Message - From: "Kent Johnson" <[EMAIL PROTECTED]> Cc: Sent: Monday, April 21, 2008 9:33 PM Subject: Re: [Tutor] Little problem with math module tiger12506 wrote: my probl

Re: [Tutor] Little problem with math module

2008-04-21 Thread Kent Johnson
tiger12506 wrote: my problem is, INSIDE the funcion...the variable erro is correct, but when i return it to the test...and the test prints itcomes out 0.0. Its disturbing...i didnt found a way of solving this. err is defined in the function so it thinks it's a local variable. My reading i

Re: [Tutor] Little problem with math module

2008-04-21 Thread tiger12506
my problem is, INSIDE the funcion...the variable erro is correct, but when i return it to the test...and the test prints itcomes out 0.0. Its disturbing...i didnt found a way of solving this. err is defined in the function so it thinks it's a local variable. You can set it to change only th

Re: [Tutor] Little problem with math module

2008-04-21 Thread Tiago Katcipis
i will change the subject but this one is interessenting. i have this test code import funcoes import bissecao import falsa_posicao import falsa_posicaom import newton_simples import math INTERVALO = [0,1] ERRO_DET = math.pow(10, -16) ITER = funcoes.calcular_num_iteracoes(INTERVALO[0], INTERVALO

Re: [Tutor] Little problem with math module

2008-04-21 Thread ALAN GAULD
On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: >>> pow(-20, 0.333) Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power >>> -20**0.333 -2.7144173455393048 >>> I think you're confusing the orde

Re: [Tutor] Little problem with math module

2008-04-21 Thread Dick Moores
At 08:17 AM 4/21/2008, Dick Moores wrote: >At 07:40 PM 4/20/2008, John Fouhy wrote: > >If you're going to be working with complex numbers, you might be > >better off looking at scipy or some other module that provides more > >mathematical grunt. > >Try mpMath () >

Re: [Tutor] Little problem with math module

2008-04-21 Thread Dick Moores
At 07:40 PM 4/20/2008, John Fouhy wrote: >If you're going to be working with complex numbers, you might be >better off looking at scipy or some other module that provides more >mathematical grunt. Try mpMath () With version 0.7: >>> from mpmath import power, mp

Re: [Tutor] Little problem with math module

2008-04-21 Thread joe gallo
On Mon, Apr 21, 2008 at 12:07 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > >>> pow(20, 0.333) > 2.7144173455393048 > >>> pow(-20, 0.333) > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > >>> -20**0.333 >

Re: [Tutor] Little problem with math module

2008-04-21 Thread Alan Gauld
"Tiago Katcipis" <[EMAIL PROTECTED]> wrote > def newton_divergente(x): > return math.pow(x, 1.0/3.0) > > but when x = -20 it returns this error > > return math.pow(x, 1.0/3.0) > ValueError: math domain error > > but why is that? is it impossible to calculate -20 ^ (1/3) ? It may be your us

Re: [Tutor] Little problem with math module

2008-04-20 Thread Tiago Katcipis
well i made a mistake again :P. i have the function x ^ 1/3, i first remembered that negative numbers do not have a square, but in this case negative numbers are ok...because it aint 1/2 ...its 1/3. Can anyone give a hint of how i can calculate it without using pow ou **? none of them work properly

Re: [Tutor] Little problem with math module

2008-04-20 Thread Tiago Katcipis
ops, now i realize the mistake i was making. Thanks for the help people Tiago Katcipis escreveu: > im not understanding why is this a problem...i have this simple function > > def newton_divergente(x): > return math.pow(x, 1.0/3.0) > > but when x = -20 it returns this error > > return math.pow(

Re: [Tutor] Little problem with math module

2008-04-20 Thread John Fouhy
On 21/04/2008, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> -1 ** (1.0/2.0) > -1.0 Replying to myself: It turns out that all is not what it seems. Let's try again: >>> (-1)**0.5 Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fraction

Re: [Tutor] Little problem with math module

2008-04-20 Thread John Fouhy
On 21/04/2008, Tiago Katcipis <[EMAIL PROTECTED]> wrote: > im not understanding why is this a problem...i have this simple function > > def newton_divergente(x): > return math.pow(x, 1.0/3.0) > > but when x = -20 it returns this error > > return math.pow(x, 1.0/3.0) > ValueError: math domain

Re: [Tutor] Little problem with math module

2008-04-20 Thread Kent Johnson
Tiago Katcipis wrote: > im not understanding why is this a problem...i have this simple function > > def newton_divergente(x): > return math.pow(x, 1.0/3.0) > > but when x = -20 it returns this error > > return math.pow(x, 1.0/3.0) > ValueError: math domain error > > but why is that? is it i

[Tutor] Little problem with math module

2008-04-20 Thread Tiago Katcipis
im not understanding why is this a problem...i have this simple function def newton_divergente(x): return math.pow(x, 1.0/3.0) but when x = -20 it returns this error return math.pow(x, 1.0/3.0) ValueError: math domain error but why is that? is it impossible to calculate -20 ^ (1/3) ? here o