comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: fractional powers of negative numbers?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: fractional powers of negative numbers? [message #8809] Mon, 28 April 1997 00:00
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Jack Saba <jsaba@magus.stx.com> writes:

> IDL is computing -(5.^1.51) in your example. If you try (-5.)^1.51, you
> will get an error.


> Med Bennett wrote:
>>
>> Can someone explain this to me? Is it possible to compute the fractional
>> power of a negative number? IDL does it on single negative values but
>> not on arrays containing negative values.
>>
>> IDL> print,findgen(11)-5
>> -5.00000 -4.00000 -3.00000 -2.00000
>> -1.00000 0.000000 1.00000 2.00000
>> 3.00000 4.00000 5.00000
>> IDL> print,(findgen(11)-5)^1.51
>> -1.#IND0 -1.#IND0 -1.#IND0 -1.#IND0
>> -1.#IND0 0.000000 1.00000 2.84810
>> 5.25355 8.11168 11.3617
>> % Program caused arithmetic error: Floating illegal operand
>> IDL> print,-2.^1.51
>> -2.84810
>> IDL> print,-5.^1.51
>> -11.3617


The only way to compute the fractional power of a negative number is to use
complex arithmetic, e.g.

IDL> print,complex(findgen(11)-5,fltarr(11))
( -5.00000, 0.00000)( -4.00000, 0.00000)
( -3.00000, 0.00000)( -2.00000, 0.00000)
( -1.00000, 0.00000)( 0.00000, 0.00000)
( 1.00000, 0.00000)( 2.00000, 0.00000)
( 3.00000, 0.00000)( 4.00000, 0.00000)
( 5.00000, 0.00000)
IDL> print,(complex(findgen(11)-5,fltarr(11)))^1.51
% Program caused arithmetic error: Floating overflow
% Detected at $MAIN$
% Program caused arithmetic error: Floating illegal operand
% Detected at $MAIN$
% Program caused arithmetic error: Floating illegal operand
% Detected at $MAIN$
( 0.356881, -11.3561)( 0.254794, -8.10767)
( 0.165018, -5.25096)( 0.0894611, -2.84669)
( 0.0314108, -0.999507)( NaNQ, NaNQ)
( 1.00000, 0.00000)( 2.84810, 0.00000)
( 5.25355, 0.00000)( 8.11168, 0.00000)
( 11.3617, 0.00000)

Interestingly enough, here it complains about taking (0,0) to a fractional
power. I would have said that (0,0) to any power was still (0,0).

Bill Thompson
Re: fractional powers of negative numbers? [message #8810 is a reply to message #8809] Mon, 28 April 1997 00:00 Go to previous message
Jack Saba is currently offline  Jack Saba
Messages: 30
Registered: January 1996
Member
IDL is computing -(5.^1.51) in your example. If you try (-5.)^1.51, you
will get an error.


Med Bennett wrote:
>
> Can someone explain this to me? Is it possible to compute the fractional
> power of a negative number? IDL does it on single negative values but
> not on arrays containing negative values.
>
> IDL> print,findgen(11)-5
> -5.00000 -4.00000 -3.00000 -2.00000
> -1.00000 0.000000 1.00000 2.00000
> 3.00000 4.00000 5.00000
> IDL> print,(findgen(11)-5)^1.51
> -1.#IND0 -1.#IND0 -1.#IND0 -1.#IND0
> -1.#IND0 0.000000 1.00000 2.84810
> 5.25355 8.11168 11.3617
> % Program caused arithmetic error: Floating illegal operand
> IDL> print,-2.^1.51
> -2.84810
> IDL> print,-5.^1.51
> -11.3617
>
> Med Bennett
> bennettm@boulder.pti-enviro.com
Re: fractional powers of negative numbers? [message #8835 is a reply to message #8809] Thu, 24 April 1997 00:00 Go to previous message
Med Bennett is currently offline  Med Bennett
Messages: 109
Registered: April 1997
Senior Member
Actually, I guess i answered my own question:

IDL> print,(-5.)^1.51
-1.#IND0
% Program caused arithmetic error: Floating illegal operand

I thought the previous syntax was unambiguous, but...
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL, Mathematica, Matlab
Next Topic: Fractals, Kalman-Filter and IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:34:59 PDT 2025

Total time taken to generate the page: 0.00459 seconds