# Legendre expansion of $r(x) = f(x)/g(x)$ using a finite number of samples from $f(x)$ and $g(x)$

I have two finite sets of events $\{x_1, ..., x_N\}$ and $\{y_1, ..., y_N\}$ that are sampled from the PDFs $f(x)$ and $g(x)$, respectively, where $x \in [-1,+1]$. I want to estimate the Legendre expansion of $r(x) = f(x)/g(x)$ using these events. What is the best method? (Note that $g(x)\neq0$ over $[-1,1]$)

• Your use of $x$ to refer to events is confusing here. Do you mean that you have sampled values $f(x_i)$ and $g(x_i)$ for $i\in{1,\ldots,N}$, and would like an expansion for the function $f(x)/g(x)$ using the Legendre polynomial basis in the $x\in[-1,+1]$ interval? – Richard Zhang Jun 2 '17 at 18:07

$$\frac{f(x)}{g(x)}\approx\sum_{n=0}^p a_n P_n(x).$$
You could interpolate your samples of $f$ and $g$ to a uniform grid on $[-1,1]$, calculate the ratios at each of these points, and then use the trapezoid rule to calculate the integral
$$\int_{-1}^1 P_n(x) \frac{f(x)}{g(x)} dx \approx \sum_j w_j P_n(x_j)\frac{f(x_j)}{g(x_j)},$$
where $\{w_j,x_j\}$ represents the quadrature weights and abscissae, respectively. Given that I don't know what the functions $f,g$ behave like, I can't say much for the accuracy of this approach beyond that it should be OK if $f/g$ is smooth.
• Thanks! I think this should work for my case. The functions $f(x)$ and $g(x)$ are not extremely smooth, although $f(x)/g(x)$ is. I guess as long as the interpolated versions of $f(x)$ and $g(x)$ are both wrong by approximately the same factor (which sounds plausible) this should cancel in the ratio – Sam Jun 6 '17 at 14:47