Finding the complementary function from a boundary value problem I have the following physics equation:
$$a = \int_0^R K_1\frac{\delta \rho}{\rho} + K_2 \frac{\delta c^2}{c^2} \,\text{d}r$$
where $a$ is a real number, $R$ is a positive real number, and $K_1,K_2,\rho$ are real functions of $r$ which spans from $0$ to $R$. Furthermore, $c^2=\Gamma_1P/\rho$ where $\Gamma_1$ and $P$ are also real functions of $r$. Here $\delta$ denotes a first-order (linearized) Lagrangian perturbation.
Edit: for clarity, $\delta f$ is really denoting the differences $f - f_2$ between two functions. In this case I know $\rho$ but not $\rho_2$, and I know $c^2$ but not $c^2_2$, etc. These functions are all solutions to a set of differential equations; I have linked to another question containing (some of) these functions in dimensionless form in the comments. In specific cases I can actually compute, e.g., $\delta \rho$, by finding two functions $\rho$ and $\rho_2$. However I am interested in the general case for an arbitrary e.g. $\rho_2$ and hence an arbitrary $\delta \rho$. However, $\rho_2$ can be assumed to have all similar kinds of properties as $\rho$, e.g., finite, nonnegative, etc.
I have computed all of $K_1, K_2, \rho, P, \Gamma_1$ via numerical simulation.
As $\int_0^R r^2 \rho\,\text{d}r$ should be conserved, we have that the complementary function for $\rho$ is $T=r^2\rho$, since $\int_0^R T \frac{\delta \rho}{\rho} = 0$.
Edit 2: Any multiple of $T$ can be added to $K_1$ and it will make no difference in $a$. We project $T$ into an orthogonal vector and remove it from $K_1$.
I am now transforming this equation to use $u\equiv P/\rho$ and $\Gamma_1$ instead of $\rho$ and $c^2$. In particular:
$$a = \int_0^R K_1\frac{\delta \rho}{\rho} + K_2 \frac{\delta c}{c} \,\text{d}r = \int_0^R K_3\frac{\delta u}{u} + K_4 \frac{\delta \Gamma_1}{\Gamma_1} \,\text{d}r.$$
Edit 3: As should be clear, $\delta u/u = \delta P/P - \delta \rho/\rho$.
According to the appendix of this paper, this can be found with
\begin{align}
    K_3 &= K_2 - P\frac{\text{d}}{\text{d}r}\left( \frac{\psi}{P} \right)\\
    K_4 &= K_2
\end{align}
where $\psi$ is a solution to the ordinary differential equation
\begin{equation}
    \frac{\text{d}}{\text{d}r}\left(
        \frac{1}{r^2\rho}
        \left(\frac{\text{d}\psi}{\text{d}r}
        -
        K_1
        \right)
    \right)
    +
    \frac{4\pi G\rho}{r^2P}\,\psi
    =
    0
\end{equation}
with boundary conditions $\psi(0)=0, \psi(R)=0$.
I am able to solve all of this numerically.
My question: how can I find (or numerically approximate) the complementary function for $u$, i.e., what is a (non-trivial) $T_2$ such that $\int_0^R T_2 \frac{\delta u}{u}\,\text{d}r = 0$?
 A: As far as your actual question is concerned, it really doesn't matter what $\frac{\delta u}u$ actually is, just that it is an integrable function on $(0, R)$. For simplicity, just call it $h(r)$. Also to simplify the mathematics a bit, let me assume it is continuous and further that $\int_0^R h^2(r)\,dr$ is also finite and non-zero.
Now consider the set $V$ of all such functions. Note that if $a, b \in \Bbb R; f, g \in V$ then $af + bg \in V$ as well. which makes $V$ a vector space. If we define $$\langle f, g\rangle = \int_0^Rf(r)g(r)\,dr$$
Then $\langle \phantom f, \phantom g\rangle$ is an inner product on $V$. We can use it to define the norm $$\|f\| = \sqrt{\langle f, f\rangle}$$
The condition you give for $T$ can now be restated as $$\langle T, h\rangle = 0$$ That is, it is a vector perpendicular to $h = \frac {\delta u}u$. But as I previously told you in another thread, and Ian has reiterated here, there is far more than a single function $T$ for which this holds.
Let $f$ be an arbitrary function in $V$. Then note that
$$\left\langle f - \dfrac{\langle f, h\rangle}{\|h\|^2}, h\right\rangle = \langle f, h\rangle - \dfrac{\langle f, h\rangle}{\|h\|^2}\langle h, h\rangle = 0$$
In integral form, that means for any continuous function $f$ with $\int_0^R f^2(r)\,dr < \infty$, letting $$T = f - \dfrac{\int_0^R f\frac{\delta u}u\,dr}{\int_0^R \left(\frac{\delta u}u\right)^2\,dr}\frac{\delta u}u$$ gives a function $T$ satisfying $\int_0^R T\frac{\delta u}u\,dr = 0$.
If all you need is just that integral relation, then you can choose an arbitrary $f$ and produce $T$ as indicated. Unless you are so amazingly unlucky as to pick a constant multiple of $\frac{\delta u}u$, the resulting $T$ will be non-trivial.
The condition that $\frac{\delta u}u$ is continuous is a convenience that can be easily loosened. The condition that $\int_0^R \left(\frac{\delta u}u\right)^2\,dr$ is finite is a little harder to remove, but arrives at the same end: there are still infinitely many independent $T$ that satisfy the condition - they just have to be constructed differently.
