[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: forcing fitted curve through a point
From: |
Rafael Laboissiere |
Subject: |
Re: forcing fitted curve through a point |
Date: |
Thu, 25 Oct 2007 21:24:46 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
* M Devoto <address@hidden> [2007-10-25 18:41]:
> is there a way to force a fitted curve through a given point? I'm using
> polyfit to find the two coefficients of a curve. I want to force it through
> (1,1). Any ideas?
Bad news and good news. The bad news, first: I am afraid you will not be
able to do it directly with polyfit. The good news: polyfit is just a
wrapper around the the left matrix division operator ("\") , so it is easy
to do it yourself. Here is the cookbook:
Let us say that you want to fit y against x using the following polynomial
model (2nd order for the sake of simplicity, but the technique can be
generalized to any order):
y = a * x * x + b * x + c
Note that you have three parameters to estimate (a, b, and c). Now, if you
force the curve to pass through (1, 1), then we are effectively introducing
a constraint that will reduce the number of parameters by one. Indeed, this
impose:
c = 1 - a - b
which yields:
y = a * (x * x - 1) + b * (x - 1) + 1
This is easily solved in Octave. Let us say that x and y are column
vectors. Then, you should just do:
coeff = [(x .* x - 1), (x - 1)] \ (y - 1)
a = coeff (1)
b = coeff (2)
c = 1 - a - b
and it is done.
--
Rafael