|
Ryan <Galaxian8@aol.com> wrote in message <31509243.1227235597914.JavaMail.jakarta@nitrogen.mathforum.org>...
> I'm writing a code where a variable RH=-2.3927e+004 and y4=0.3500. In my code RH^y4 spits out a complex number. When I was debugging the code I tried just running the numbers w/o the variables I got the correct answer. Is there something syntax rule I'm missing or how should I code this?
--------
You are taking a fractional power of a negative number and that will almost always lead to complex results. For example the 1/2 power of -1 is plus or minus the square root of -1, or plus or minus i, which is either of two complex values. With a power of .35 = 20/7 there are seven possible answers, all of them complex-valued.
Mathematicians get around this ambiguity by defining
y^x = exp(x*log(y))
where the log function has infinitely many branches in the complex plane. In Matlab the 'log' function selects the branch with imaginary part equal to pi*i for negative values of y, which generally results in a complex-valued result.
Roger Stafford
|