A matrix method is far simpler I suppose:
h x x1 x2 x3
h1 ⌈x1*h1 x2*h1 x3*h1 ⌉
h2 |x1*h2 x2*h2 x3*h2|
h3 ⌊x1*h3 x2*h3 x3*h3 ⌋
h x 3 2 1
1 ⌈3 2 1 ⌉
-2 |-6 -4 -2|
3 ⌊9 6 3 ⌋
Now just add up the diagonals:
y[0] = 3
y[1] = -4
y[2] = 6
y[3] = 4
y[4] = 3
p.s I don't know how to type in a matrix here.