I have to integrate expression f(x) * g(x)
for many different functions f
but just one g
.
I want to integrate it as sum of weighted values of f(x) * g(x)
instead of calculating the table. Note that in Python I may write:
sum(w[i] * f(x[i]) * g(x[i]) for i in range(2 ** k + 1))
as:
wg = [w[i] * g(x[i]) for i in range(2 ** k + 1)]
sum(wg[i] * f(x[i]) for i in range(2 ** k + 1))
where w[i]
are weights of function values used by the Romberg method which may be calculated like:
import numpy as np
from scipy.integrate import romb
w = romb(np.eye(2 ** k + 1))
Is such implementation of Romberg method safe?
(The question has been also asked at CS: https://scicomp.stackexchange.com/questions/35469/is-romberg-integration-method-implemented-as-weighted-function-values-numericall)