Ariel Pacetti on Wed, 14 Apr 2010 11:09:42 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Bug, or what am I missing? |
If you look at the documentation it says:If the exponent is not of type integer, this is treated as a transcendental function (see Section 3.3), and in particular has the effect of componentwise powering on vector or matrices.
So what it means is that what it is computing is exactly: exp(log(-8)/3) ? exp(log(-8)/3)%1 = 1.0000000000000000000000000000000000000 + 1.7320508075688772935274463415058723669*I
This is not a bug, since you have 3 solutions to you problem (you are looking at the roots of x^3+8, and there are 3 of them), the point is that you have to make a choice in the answer. It depends on which branch of the logarithm you are taking. If you start with a positive integer, you don't have this problem, since the first solution lies in the real line.
So an ugly way to get the answer you are looking for (for odd exponent denominators) is to add an absolute value and the sign in the final answer:
-(abs(8))^(1/3) ? -(abs(8)^(1/3)) %2 = -2.0000000000000000000000000000000000000 Ariel On Wed, 14 Apr 2010, Ryan Voots wrote:
While I find it hard to believe that you guys could have overlooked this (I suspect that it has got to be something I need to do or something I'm unaware of) ? (-8)^(1/3) %1 = 1.0000000000000000000000000000000000000 + 1.7320508075688772935274463415058723669*I I'd expect to get -2 here instead of an imaginary number. Increasing the precision doesn't seem to help (just adds more digits). Interestingly this number appears to be related to the correct answer. If you take it and multiply by its conjugate and then take the square root you'll get close to the answer (just wrong sign). ? (-8)^(1/3) %2 = 1.000000000000000000000000000 + 1.732050807568877293527446342*I ? (1.000000000000000000000000000 + 1.732050807568877293527446342*I) * (1.000000000000000000000000000 - 1.732050807568877293527446342*I) %3 = 4.000000000000000000000000002 + 0.E-38*I ? (4.000000000000000000000000002 + 0.E-38*I)^(1/2) %4 = 2.000000000000000000000000001 What am I missing here to be getting the correct answer?