Why it comes up with the imaginary number?

I found a very simple calculation but two different results:
1) -0.6^0.1 = 0.9502
2)
g=-0.6;
gg=0.1
g.^gg = 0.9037 + 0.2936i
Does anyone have an idea what's going on here?

 Accepted Answer

The first raises 0.6 to the 0.1 power, then negates it.
The second takes -0.6 to the 0.1 power, and taking a non-integer power of a negative value creates a complex result.
G1 = -0.6^0.1
G1 = -0.9502
G2 = (-0.6)^0.1
G2 = 0.9037 + 0.2936i
.

4 Comments

Further to this:
in MATLAB, the negative sign in -0.6 is not generally processed as "syntax" for a negative number. Instead, it is processed as the "unary minus" operation applied to 0.6. This is the same operation that is used for
y = -x
MATLAB does not process that -x as being an implicit 0 before, not treated as 0-x and instead it is a separate operator (there are built-in hardware operations for negating a floating point number that do not require using the arithmetic logic unit.)
So with the - in -0.6 being treated as an operator, questions arise about priority of operations when the 0.6 is followed by an operation. It happens that in MATLAB, the unary minus operator is lower priority than ^ so -0.6^2 would be unary minus applied to (0.6^2) . This does take some getting accustomed to, but it means that if you write -x^2 it means to take the negative of x^2 rather than meaning to take the negative of x and square that. And that in turn means that 0-x^2 is consistent in result (generally) with -x^2 as people would expect: square first and then do the negative.
Thanks a lot! This helps and teaches me more than I expected :)
As always, my (our) pleasure!
Also note that raising a negative number to a fractional power is actually multi-valued, and MATLAB only gives one of the possible results. Rearranging calculations into something that looks mathematically the same can often result in a different answer in these situations. E.g., a few of the possibilities for this specific example:
format longg
x1 = (-0.6)^0.1
x1 =
0.903694107692789 + 0.293628014959008i
x2 = 0.6^0.1 * exp(pi*i/10)
x2 =
0.903694107692789 + 0.293628014959008i
x3 = 0.6^0.1 * exp(3*pi*i/10)
x3 =
0.558513673987152 + 0.768728123211847i
x4 = 0.6^0.1 * exp(5*pi*i/10)
x4 =
5.81829826846399e-17 + 0.950200216505676i
x1^10
ans =
-0.6
x2^10
ans =
-0.6
x3^10
ans =
-0.6 - 5.55111512312578e-17i
x4^10
ans =
-0.6 + 3.67394039744206e-16i
All of x1, x2, x3, and x4 are 10th roots of -0.6. In this case, x3 and x4 suffer a bit of round-off error in the calculations, but they get essentially the same answer as x1 and x2 when raised to the power of 10.

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Math in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!