# Second order 1D equation with integral boundary condition

Is it possible to solve below equation in Mathematica in range $0<x<r$?

$f''[x] + \frac{2f'[x]}{x} = -A e^{-B f[x]}$

$f'[x]|_{x=r}=-\alpha\:\:\:\:\:$ and $\:\:\:\int_0^r f(x) x^2 dx= \gamma$

$A$,$B$,$\alpha$,$\gamma$ and $r$ are real known parameters.

I think NDSolve should help but I don't know how to account for integral boundary condition. Any help is really appreciated.

• People here generally like users to post code as Mathematica code instead of TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you.I would be good if you can add the missing parameters, otherwise people will most likely not want to try. Commented May 15, 2018 at 14:38
• Thank you for your comment. I will do that @MariuszIwaniuk Commented May 15, 2018 at 15:34

Approximate solution by Series with 1 term.

Linearizing function Exp[-B f[x]] with series in point r/2:

linear = (Series[-A*Exp[x], {x, r/2, 1}] // Normal) /. x -> -B f[x]
sol = f[x] /. DSolve[{f'[r] == -α, f''[x] + 2*f'[x]/x == linear}, f[x],x][[1]]


Integral boundary condition:

sol1 = Integrate[sol*x^2, {x, 0, r}] == γ


Finding const C[1]:

sol2 = Solve[sol1, C[1]]


Symbolic solution f[x] :

solution = sol /. sol2[[1]] // Simplify

(* (E^(-((3 r)/4) - 5 Sqrt[A] Sqrt[B] E^(r/4) r -
Sqrt[A] Sqrt[B] E^(r/4)
x) (-6 Sqrt[A] Sqrt[B] E^(r + 6 Sqrt[A] Sqrt[B] E^(r/4) r)
r (-E^(Sqrt[A] Sqrt[B] E^(r/4) (r + x)) (-2 + r) x -
B r^2 \[Alpha] +
2 B E^(Sqrt[A] Sqrt[B] E^(r/4) r) r^2 \[Alpha] +
B E^(2 Sqrt[A] Sqrt[B] E^(r/4) x) r^2 \[Alpha]) +
3 E^((3/4 + 5 Sqrt[A] Sqrt[B] E^(r/4)) r) (-1 + E^(
Sqrt[A] Sqrt[B] E^(r/4)
r)) (-E^(Sqrt[A] Sqrt[B] E^(r/4) x) (-2 + r) x -
E^(Sqrt[A] Sqrt[B] E^(r/4) (r + x)) (-2 + r) x +
2 B E^(Sqrt[A] Sqrt[B] E^(r/4) r) r^2 \[Alpha] +
2 B E^(2 Sqrt[A] Sqrt[B] E^(r/4) x) r^2 \[Alpha]) -
2 A^(3/2) B^(3/2) E^((3/2 + 7 Sqrt[A] Sqrt[B] E^(r/4)) r)
r (-2 r^3 + r^4 + 6 B \[Gamma]) +
A^2 B^2 E^((7/4 + 5 Sqrt[A] Sqrt[B] E^(r/4)) r) (E^(
2 Sqrt[A] Sqrt[B] E^(r/4) r) + E^(
2 Sqrt[A] Sqrt[B] E^(r/4) x)) r^2 (-2 r^3 + r^4 +
6 B \[Gamma]) +
A B E^((5 r)/4 +
5 Sqrt[A] Sqrt[B] E^(r/4)
r) (-3 E^(Sqrt[A] Sqrt[B] E^(r/4) x) (-2 + r) r^2 x -
3 E^(Sqrt[A] Sqrt[B] E^(r/4) (2 r + x)) (-2 + r) r^2 x +
E^(2 Sqrt[A] Sqrt[B] E^(r/4)
x) (2 r^3 + r^4 (-1 + 6 B \[Alpha]) - 6 B \[Gamma]) +
E^(2 Sqrt[A] Sqrt[B] E^(r/4)
r) (-2 r^3 + r^4 (1 + 6 B \[Alpha]) +
6 B \[Gamma]))))/(6 B (-1 + Sqrt[A] Sqrt[B] E^(r/4) r) (1 -
E^(2 Sqrt[A] Sqrt[B] E^(r/4) r) + Sqrt[A] Sqrt[B] E^(r/4) r +
Sqrt[A] Sqrt[B] E^(r/4 + 2 Sqrt[A] Sqrt[B] E^(r/4) r) r) x)*)

r = 1; (* A random values *)
A = 1;
B = 1;
α = 1;
γ = 1;
Plot[solution, {x, 0, r}, PlotRange -> {Automatic, {20, 2}}]


EDIT: 06.07.2018

Numeric solution:

I assume a dummy boundary condition like f[1] == c then I only need to find c by FindRoot.

r = 1;(*Assume values*)
A = 1;
B = 1;
\[Alpha] = 1;
\[Gamma] = 1;

sol3[c_?NumericQ] := NDSolve[{f'[r] == -\[Alpha], f[1] == c,
f''[x] + 2*f'[x]/x == -A*Exp[-B*f[x]]}, f, {x, 1/10000, 1}]

INT[c_?NumericQ] := NIntegrate[(f[x] /. sol3[c])*x^2, {x, 0, r},

search = c /. FindRoot[INT[c] == \[Gamma], {c, 1, 10}, Method -> "Secant"]
(* c is: 2.5066 *)


Check boundary condition f'[1] == -1 and Integrate[f[x]*x^2, {x, 0, 1}] == 1 :

D[(f[x] /. sol3[search]), x] /. x -> 1
(* -1. *)(* OK *)
NIntegrate[(f[x] /. sol3[search])*x^2, {x, 0, r}, Method -> "LocalAdaptive"]
(* 1. *)(* OK *)

Plot[{solution, Evaluate[f[x] /. sol3[search]]}, {x, 1/10000, r},
PlotLegends -> {"symbolic only with 1 term", "numeric"}]


It seems 1-term not really enough to good approximate solution,need more terms.

• Sorry, but I didn't understand why it is not accurate. Commented May 15, 2018 at 15:33
• @HolgerMate. I took only 1 term $\exp (x)\approx 1+x$ Commented May 15, 2018 at 15:40
• @HolgerMate .I edited my answer. Commented Jul 6, 2018 at 20:30