log10(x)^y with 0 < x < 1 and 0 < y < 1 gives NaN for unknown reasons


for some reason R is giving me NaN for the following input:

> log10(0.1)^0.5
[1] NaN

If x or y are >1, everything works fine:

> log10(0.1)^2
[1] 1
> log10(100)^0.5
[1] 1.414214

Also typing every single result of the input isn't a problem:

> log10(0.1)
[1] -1
> -1^0.5
[1] -1

Am I missing something? R does this every time, when x and y are between 0 and 1. Am I overlooking an obvious fault? Every help is appreciated.

Did you try (-1)^0.5 ?
And what about the square root of a negative number?

Following along with @HanOostdijk, the difference is whether R thinks it's dealing with a floating point number or an integer. In general, a fractional power of a negative number is undefined.

I see. Trying the examples of @HanOostdijk I received NaNs. I think I can deal with it multiplying log10(x) by -1 before and then multiplying again by -1 after ^0.5

Could you tell us what you want to do?
Why do you want to calculate log10(x)^y for the indicated ranges for x and y ?

But the square root of -1 is not -1, it's an imaginary number.

I wanted to produce an adsorption-isotherm after Freundlich, that has the form
Y = Kfr * X^(1/n)
with the nlsLM()function. Since I wanted to add the resulting fit into a log-scaled figure, I adjusted the formula like this: log10(Y) = Kfr *log10(X)^(1/n)
The input values of X and Y lay between zero and one. Anyway I'm also having troubles finding good starting points for Kfr and n, but that's another issue. Now seeing that log10(0<X<1)is a negative number and the fractional power of a negative number is undefined - as mentioned by @startz - I thought I can avoid it by doing this:
log10(Y) ~ Kfr * (-1*((-1*log10(X))^(1/n)))

Okay, now I understand where the formula is derived from. But

Y = Kfr * X^(1/n)
log10(Y) = log10(Kfr) +log10(X)*(1/n)

Haha I wasn't sure to be honest. But forget about it. With log-scaled axes I can simply use a linear model to fit the data and it works just fine. Anyway thanks for your help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.