Skip to content

Obtaining a quadratic function igven three points on a curve

4 messages · Barth B. Riley, David Scott, Joshua Wiley

#
Hello

I would like to obtain the coefficients for a quadratic function (ax^2 + bx + c) given three sets of points on the quadratic curve. For instance:

Y                       X
0.159529                0
0.5                     0.773019
1                       1

Is there a function in R to obtain the a, b and c ceofficients?

Thanks

Barth

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.
#
Hi Barth,

Here is an option fitting a linear model toa  second order polynomial
and extracting the coefficients.  The Intercept corresponds to "c" in
your email, then poly(...)1 to "b" and poly(...)2 to "a".

################
dat <- read.table(textConnection("
Y X
0.159529 0
0.5 0.773019
1 1"), header = TRUE)
closeAllConnections()

coef(lm(Y ~ poly(X, 2), data = dat))
#################

For details see:

?poly
?lm
?coef

Hope this helps,

Josh
On Thu, Jan 20, 2011 at 6:42 AM, Barth B. Riley <bbriley at chestnut.org> wrote:

  
    
#
I think you need poly(X, 2,  raw = TRUE) to interpret the coefficients 
in the manner described below.

poly uses orthogonal polynomials by default:

poly                   package:stats                   R Documentation

Compute Orthogonal Polynomials

Description:

      Returns or evaluates orthogonal polynomials of degree 1 to
      'degree' over the specified set of points 'x'. These are all
      orthogonal to the constant polynomial of degree 0.  Alternatively,
      evaluate raw polynomials.


David Scott
On 21/01/2011 3:50 a.m., Joshua Wiley wrote:

  
    
#
Many thanks for the correction David.

Josh
On Thu, Jan 20, 2011 at 7:17 AM, David Scott <d.scott at auckland.ac.nz> wrote:
[snip]