I would like to define a function that does the following.
If I have an equation, for example:
$$f(x)+[1-f^2(x)]+f^{\prime\prime}(x)+f(x)\ f^\prime(x)=0$$
and I am given a value for $f$ to expand about, say $\bar f$, I want the function to substitute $$f\rightarrow\bar f+\delta f$$ substitute it in the initial equation, and give me only the equation for $\delta f$, keeping terms up to order (given by me as argument $n$). For example, for $n=1$:
$$\delta f(x)+[1-\bar f^2(x)-2\bar f \delta f(x)]+\delta f^{\prime\prime}(x)+\bar f \delta f^\prime(x)=0$$
I usually do this by expanding with an $\epsilon$ in front of $f$ and then taking a series in $\epsilon$ small. At the end I impose $\epsilon=1$:
n = 1;
eq = f[x] + (1 - f[x]^2) + D[f[x], x, x] + f[x] D[f[x], x];
f[x_] = f0 + ϵ df[x];
eq1 = Normal[Series[eq, {ϵ, 0, n}]];
eqFin = eq1 /. ϵ -> 1 // FullSimplify
I would like to know if there is a more efficient way to do it, and how to embed all this in a function definition.
Summarising, the input would be:
- equation for $f$
- base state $\bar f$
- order of the expansion $n$
the output would be the new equation.
Edit:
I would also be interested in a generalisation to more than one variable and more than one function, for example in the case of a system of two coupled equations in f[x,y]
, g[x,y]
where both f
and g
need to be expanded up to order $n$.