Question

Let's assume we have following matrix and want to build the power of 1.5 that is b^1.5 :

b <- matrix(c(1,2,4,4,-0.6,56), ncol=1)
b^1.5

           [,1]
[1,]   1.000000
[2,]   2.828427
[3,]   8.000000
[4,]   8.000000
[5,]        NaN
[6,] 419.065627

but

-0.6^1.5
[1] -0.464758

Is anyone aware of solution of this kind a problem?

Was it helpful?

Solution

-0.6^1.5 is not the same as (-0.6)^1.5.

From help("^"):

Users are sometimes surprised by the value returned, for example why (-8)^(1/3) is NaN. For double inputs, R makes use of IEC 60559 arithmetic on all platforms, together with the C system function pow for the ^ operator. The relevant standards define the result in many corner cases. In particular, the result in the example above is mandated by the C99 standard. On many Unix-alike systems the command man pow gives details of the values in a large number of corner cases.

What do you want the result to be?

OTHER TIPS

This has to do with the order of evaluation in R.

-0.6^1.5 is really 0.6^1.5 times -1. The exponent is evaluated before the negative.

When you put the -0.6 into the matrix, the negative is applied to 0.6 when b is created. That means that when you take the exponent, you are really doing this:

(-0.6)^1.5
# NaN
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top