[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Getting complex numbers results instead of expected real numbers
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Getting complex numbers results instead of expected real numbers |
Date: |
Sun, 12 Feb 2012 09:48:37 -0500 |
On 12 February 2012 09:19, ant <address@hidden> wrote:
> When running a script in Octave 3.4.3, I'm getting complex numbers of the
> form (a+0.0000i) or (a-0.0000i), instead of the expected real number a. Any
> help will be much appreciated!
[snip]
> y1 =
> l2m*(r-mu)*(l1p-l1m)*(phistar*k0+(gama+delta*k0)/r-c0/r*(xtau/c0)^l2p)-((l2m-1)*(l1p-l1m)-l1m*(1+l1p-l2m)*(xtau/c0)^l1p)*xtau;
This expression can potentially raise negative numbers to powers. For
example, insert the following debugging lines in this function:
if (iscomplex(y1))
keyboard;
endif
You will observe that this sometimes results in xtau/c0 being
negative, so you get a complex result with small imaginary part when
raising it to l1p.
If you want to avoid complex results when raising to powers, sometimes
the following functions can help: realpow, realsqrt, cbrt, nthroot.
HTH,
- Jordi G. H.