I have the following function for cubic interpolation:
f(y0,y1,y2,y3,x) = y1+x/2*(y2-y0+x*(2y0-5y1+4y2-y3+x(3*(y1-y2)+y3-y0)))
I need to figure out the average of that function across some range of x, [xmin, xmax], typically 0-1, and I assume the best way would be to integrate.
I am currently just sampling the function many times across the range, which is stupid and computationally expensive.
I'd like to not be stupid about it, but since I am I guess I'll have to ask for help :)
Thanks <3
As far as I understand, yi
are parameters here, constants. So transform current form (Horner's scheme) to polynomial expression, using a,b,c,d
coefficents (expressions with yi
)
y1+x/2*(y2-y0+x*(2y0-5y1+4y2-y3+x(3*(y1-y2)+y3-y0))) =
y1 + x*1/2*(y2-y0) + x^2*1/2*(2y0-5y1+4y2-y3) + x^3*1/2*(3*(y1-y2)+y3-y0) =
a b c d
a + x*b + x^2*c + x^3*d
and integrate it
I(x) = a*x + x^2/2*b + x^3/3*c + x^4/4*d + Const
Now definite integral over 0..1 x-interval is (re-check my calculations)
a + 1/2*b + 1/3*c + 1/4*d =
y1 + 1/4*(y2-y0) + 1/6*(2y0-5y1+4y2-y3) + 1/8*(3*(y1-y2)+y3-y0) =
y0*(-1/4+1/3-1/8) + y1*(1-5/6+3/8) + y2*(1/4+2/3-3/8) + y3*(-1/6+1/8)=
y0*(-1/24) + y1*13/24 + y2*13/24 + y3*(-1/24)=
(-y0 + 13*y1+11*y2-y3) / 24
Integration over arbitrary intervals x1..x2
is performed by similar way
DefiniteIntegral(x1..x2) = I(x2) - I(x1)
and average
Av = DefiniteIntegral(x1..x2) / (x2-x1)