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.


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$.

  • 1
    $\begingroup$ At the very least, provide the complete desired result. And some code too ... $\endgroup$ Jan 21, 2016 at 16:29
  • $\begingroup$ I added the desired result, and explained how I usually do it. $\endgroup$ Jan 21, 2016 at 16:45
  • $\begingroup$ And also entered the code that does what I want, but 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. $\endgroup$ Jan 21, 2016 at 16:54
  • $\begingroup$ Related: Multivariable Taylor expansion does not work as expected $\endgroup$
    – Jens
    Jan 22, 2016 at 3:17

1 Answer 1

linearizeEquation[expr_, f_, fp_, order_] := Block[{e},
   Expand@Normal@Series[expr /. f -> (fp + e dF[#] &), {e, 0, order}] /. e -> 1
linearizeEquation[f[x] + (1 - f[x]^2) + D[f[x], {x, 2}] + f[x] D[f[x], x], f, f0, 1]
(* 1 + f0 - f0^2 + dF[x] - 2 f0 dF[x] + f0 dF'[x] + dF''[x] *)
  • $\begingroup$ Perturbation of order n? $\endgroup$ Jan 21, 2016 at 17:21
  • $\begingroup$ @Dr.belisarius. It seems that the OP wants to vary the order of the expansion, not the order of the perturbation. Am I missing something? $\endgroup$
    – march
    Jan 21, 2016 at 17:23
  • $\begingroup$ Well, it looks like a perturbation to me. Bah, doesn't matter. +1 $\endgroup$ Jan 21, 2016 at 17:28
  • 1
    $\begingroup$ @Dr.belisarius. Thank you for the apathetic-pity-+1. :) $\endgroup$
    – march
    Jan 21, 2016 at 17:29
  • 1
    $\begingroup$ @Dr.belisarius. My apathy is a contagious disease, but it's treatable. $\endgroup$
    – march
    Jan 21, 2016 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.