[R] Solving quadratic equation in R

Thu Jul 26 23:56:30 CEST 2012

```Hello,

Surely one of

f <- function(a) a^2 - a - 8.313

curve(f, from=0, to=1)
# zeros of f
root <- polyroot(c(-8.313, -1, 1))
ifelse(Im(root) == 0, Re(root), root)
# minimum of f
optimize(f, interval=c(0, 1))

Hope this helps,

Em 26-07-2012 22:13, Nordlund, Dan (DSHS/RDA) escreveu:
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Diviya Smith
>> Sent: Thursday, July 26, 2012 1:50 PM
>> To: r-help at r-project.org
>> Subject: Re: [R] Solving quadratic equation in R
>>
>> Sorry it is important for me to constrain the value of 'a' between
>> c(0,1)
>>
>> On Thu, Jul 26, 2012 at 4:48 PM, Diviya Smith
>> <diviya.smith at gmail.com>wrote:
>>
>>> Hi there,
>>>
>>> I would like to solve a simple equation in R
>>>
>>> a^2 - a = 8.313
>>>
>>> There is no real solution to this problem but I would like to get an
>>> approximate numerical solution. Can someone suggest how I can set
>> this up?
>>> Diviya
>>>
> What is your definition of approximate?  For all values of a in the interval [0,1], a^2-a is less than or equal to 0.  Or am I missing something?
>
> Dan
>
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help