help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What does power operator ^ returns?


From: Guido Walter Pettinari
Subject: Re: What does power operator ^ returns?
Date: Mon, 19 Oct 2009 23:58:38 +0000

Thank you for all the answers! I will stick to the sign-abs trick for the time being, even though the 'root' solution Doug pointed out is really cool :)

@Jaroslav
Thank you for explaining this strange behaviour. I tried to use the nthroot function instead of the hat operator but, as you pointed out, the calculations were much slower.

Cheers,

Guido

On Oct 19, 2009, at 19:17 , <address@hidden> wrote:



> From: address@hidden
> Subject: What does power operator ^ returns?
> Date: Mon, 19 Oct 2009 16:42:06 +0000
> To: address@hidden
>
> Hi all!
>
> I need to compute the cubic root of many negative numbers. My problem > is real-valued, hence I am not interested in the imaginary solutions.
> However, if I use the power operator '^', Octave returns just the
> first imaginary solution. The same applies when doing any odd root.
>
> Example:
> octave> a=-8
> a = -8
> octave> a^(1/3)
> ans = 1.000000000000000e+00 + 1.732050807568877e+00i
>
> How can I make octave to return the real solution, which in my example > is just -2? I do not want just the absolute value (i.e. abs(a^ (1/3)),
> since it does not preserve the sign. I could do with a check on the
> sign, but it would be inefficient.
>
> I am using Octave 3.2.3 on Mac Os X 10.6.
>
> Thank you very much,
>
> Guido
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave



if you want to see all the roots try

roots([1 0 0 8])

that will give you all the cube roots of -8

and roots([1 0 0 0 0 8])
will give you all 5,   fifth roots of -8
:-)

Doug







reply via email to

[Prev in Thread] Current Thread [Next in Thread]