onsdag 11 juni 2014

Finding maximum correction for three samples

I always recalculate this when I need it, but now it is time to save it somewere.


You have three samples y1 y2 y3. and you want to know there the maximum is, if you do a quadratic regression from it. We here assume that the distance between the points in the x-axis is 1.

First, lets do the quadratic regression
We describe the graph as y = ax² + by + c

So we want the values of a, b and c

for y2 = y(x = 0) we have
y2 = a·0 + b·0 + c → 
c = y2

We then have that 
y1 = y(-1) = a·(-1)² + b·(-1) + c →
y1 = a - b + c →   (c = y2)
y1 = a - b + y2

and also in a similar fashion 
y3 = y(1) = a·1² + b·1 + c →
y3 = a + b + y2

Therefore we can take
y3 - y1 = 2b →
b = (y3 - y1) / 2

and
y1 + y3 = 2a + 2c = 2a + 2y2
2a = y1 + y3 - 2y2
a = (y1 + y3)/2 - y2


To get the maximum of the graph, we just have to find the zero of the derivative y'.
y = ax² + bx + c →
y' = 2ax + b

0 = y'
0 = 2ax + b
0 = 2((y1 + y3) / 2 + y2)·x + (y3 - y1)/2
2((y1 + y3) / 2 - y2)·x = -(y3 - y1)/2
(y1 + y3 - 2y2)·x = (y1 - y3)/2
x =  (y1 - y3) / (y1 + y3 - 2y2) / 2

...Done once for all.


Inga kommentarer:

Skicka en kommentar