[R-sig-teaching] Plot f(x) = x^(1/5)
Klaus Langohr
klaus.langohr at upc.edu
Tue May 17 18:10:13 CEST 2016
Hi,
The powerplus package does raise a negative number to a fractional
power. Try:
library(powerplus)
explus(-.5, 1/5)
Klaus.
On 17/05/2016 17:55, Albyn Jones wrote:
> I think R is doing just what it should do, and the TI has been hacked to
> make HS teachers happy :-)
>
>> log(as.complex(-2))/5
> [1] 0.1386294+0.6283185i
>> a <- log(as.complex(-2))/5
>> exp(a)^5
> [1] -2-0i
>
>> exp(a)
> [1] 0.9293165+0.675188i
>> (as.complex(-2))^(1/5)
> [1] 0.9293165+0.675188i
>> 2^(1/5)*cos(pi/5)
> [1] 0.9293165
>> 2^(1/5)*sin(pi/5)
> [1] 0.675188
>
> albyn
>
>
> On Tue, May 17, 2016 at 8:10 AM, Richard M. Heiberger <rmh at temple.edu>
> wrote:
>
>> This problem is an example of FAQ 7.31. Floating point numbers
>> inside the computer can not represent odd fractions exactly.
>>
>>> seq(1, 15, 2)
>> [1] 1 3 5 7 9 11 13 15
>>> 1/seq(1, 15, 2)
>> [1] 1.00000000 0.33333333 0.20000000 0.14285714 0.11111111 0.09090909
>> 0.07692308
>> [8] 0.06666667
>>> print(1/seq(1, 15, 2), digits=18)
>> [1] 1.0000000000000000000 0.3333333333333333148 0.2000000000000000111
>> [4] 0.1428571428571428492 0.1111111111111111049 0.0909090909090909116
>> [7] 0.0769230769230769273 0.0666666666666666657
>>> ## except for 1, none of these odd fractions is exactly represented
>> inside the computer.
>>> ## therefore the power requested is not the exact fraction, and the
>> result is not capable of calculation
>>> (-2)^(1/seq(1, 15, 2))
>> [1] -2 NaN NaN NaN NaN NaN NaN NaN
>> Rich
>>
>> On Tue, May 17, 2016 at 10:23 AM, bob at statland.org <bob at statland.org>
>> wrote:
>>> Forwarded message:
>>>>>> System is working correctly. A negative number cannot be raised to a
>>>>>> fractional power:
>>>>>>
>>>>>>> (-2)^(1/5)
>>>>>> [1] NaN
>>> Well, maybe we should say that _R_ can't raise a negative number to a
>>> fractional power. Neither I nor the TI calculators have any trouble
>>> doing it;-) I'd say R is funtioning as designed, but it was designed
>>> to respond INcorrectly;-)
>>>
>>> This R exchange
>>>
>>>> (-2)^5
>>> [1] -32
>>>
>>> shows that -2 is a fifth root of -32 while this exchange
>>>
>>>> (-32)^(1/5)
>>> [1] NaN
>>>
>>> shows that R cannot find that root. The various suggestions for
>>> dealing with this amount to asking R a different question which we
>>> know has the same answer as the intended question (which R won't
>>> answer).
>>>
>>> On one level you could view this as a coding/implementation issue. I
>>> have not looked at R's code, but the usual computer way to handle
>>> exponents involves taking the log of the argument. This does not
>>> return the correct answer when the argument is negative. That's
>>> annoying. The TI graphing calculators were developed with an
>>> incredible amount of input from secondary math. teachers. They
>>> complained loudly about calculators returning wrong answers or
>>> non-answers to problems to which students knew the right answers. TI
>>> did a LOT of work on this. I wish R (and lots of scientific software)
>>> would do likewise.
>>>
>>> On another level, involving exponentiation is not entirely avoidable.
>>> For rational numbers like 1/5 we can (and usually do) interpret
>>> (-32)^(1/5) as a name for a real number that when raised to the fifth
>>> power gives -32. Another name for one such number is -2. But if we want
>>> to use an irrational exponent, say (-32)^pi we can't interpret it that
>>> way. (How do we multiply pi numbers together?) So eventually we have
>>> to either exponentiate or have a funciton that is undefined at many
>>> points. At lesat in theory. As far as computers and calculators are
>>> concerned, they cannot represent irrational numbers anyway --
>>> eveything is a rational approximation.
>>>
>>> So I think the defect is in R, not in the original posted question.
>>>
>>> -------> First-time AP Stats. teacher? Help is on the way! See
>>>
>> http://courses.ncssm.edu/math/Stat_Inst/Stats2007/Bob%20Hayden/Relief.html
>>> _
>>> | | Robert W. Hayden
>>> | | 614 Nashua Street #119
>>> / | Milford, New Hampshire 03055 USA
>>> | |
>>> | | email: bob@ the site below
>>> / x | website: http://statland.org
>>> | /
>>> ''''''
>>>
>>> _______________________________________________
>>> R-sig-teaching at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>> _______________________________________________
>> R-sig-teaching at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
--
----------------------------------------------------
Klaus Langohr
Departament d'Estadística i Investigació Operativa
Universitat Politècnica de Catalunya
Edifici C5 (Campus Nord)
C/ Jordi Girona, 1-3
E-08034 Barcelona
Tel: (+34) 934 017 034
Fax: (+34) 934 015 855
----------------------------------------------------
[[alternative HTML version deleted]]
More information about the R-sig-teaching
mailing list