s-news
[Top] [All Lists]

Re: roots of negative numbers

To: <P.J.Wells@open.ac.uk>
Subject: Re: roots of negative numbers
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
Date: Wed, 19 Sep 2001 19:49:41 +0100 (BST)
Cc: <s-news@wubios.wustl.edu>
In-reply-to: <F9D44AC0D89CD311B9E3000629385C40044D9CAD@marconi.open.ac.uk>
Just make your numbers complex:

test <- -9
n <- 2
root.test <- (test+0i)^(1/n)
> root.test
[1] 1.83697e-16+3i

(Oh well, rounding error hits again.)

On Wed, 19 Sep 2001 P.J.Wells@open.ac.uk wrote:

> How can I get S-Plus to do (something like) the following?
>
> #take a negative number
>
> >test_ -x
>
> #take its square root
>
> >root.test_test^(1/n)
>
> #get positive root
>
> >root.test
> >-[x^(1/n)]
>
> #e.g.
>
> >test_ -9
> >root.test_test^(1/2)
> >root.test
> >-3
>
> Julian Wells
> OU Business School
> The Open University
> Walton Hall
> Milton Keynes
> MK7 6AA
> United Kingdom
> +44 1908 654658
>
>
>
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>