# $\min \int_{0}^{\infty} (a f'(x)^2+b f(x)^2+c |f(x)|) dx$

Can Mathematica solve

$$\min_{f(x) s.t. f(0)=f_0} \int_{0}^{\infty} (a f'(x)^2+b f(x)^2+c |f(x)|$$)dx ?

I tried

Needs["VariationalMethods"]
DSolve[EulerEquations[a f'[x]^2 + b f[x]^2 + c Abs[f[x]],f[x],x],f[x],x]


but I don't know what to do with the result

Solve[(\int_{1}^{f[x]}\frac{1}{Sqrt{C{1]+2(\frac{cAbs[K]}{2a}+\frac{bK^2}{2a})}}dK)^2==(x+C)^2,f[x])


PS: Sorry for the bad math formatting, I can't use math blocks. This is an old problem: "Your post appears to contain code that is not properly formatted as code" with math blocks

• Please post the output of your code by direct copy-paste, don't try to LaTeXify it. – corey979 Oct 7 at 17:51
• @corey979 The output is a visual formula. Should I take a screenshot? – Bananach Oct 7 at 17:58
• closed form solution? – Xminer Oct 7 at 18:38
• @Xminer Yes, if possible – Bananach Oct 7 at 19:29
• do you have any additional condition for variable,$a$,$b$,$c$ and function $f(x)$ itself? – Xminer Oct 7 at 19:35

# DSolve solution for positive/negative halfplane

Needs["VariationalMethods"]
eulereqs = EulerEquations[a f'[x]^2 + b f[x]^2 + c Abs[f[x]], f[x], x]

(* Out[] *)
2 b f[x] + c Abs'[f[x]] - 2 a f''[x] == 0


DSolve can't solve this right away because of the Abs'[x] term, but if we assume f[x] > 0 (or f[x] < 0 to the same effect) we can get solution families for the positive and negative half-plane.

eqpos = FullSimplify[eulereqs, f[x] > 0]
eqneg = FullSimplify[eulereqs, f[x] < 0]
DSolve[eqpos, f[x], x]
DSolve[eqneg, f[x], x]

(* Out[]*)
c + 2 b f[x] == 2 a f''[x]
c + 2 a f''[x] == 2 b f[x]
{{f[x] -> -(c/(2 b)) + E^((Sqrt[b] x)/Sqrt[a]) C + E^(-((Sqrt[b] x)/Sqrt[a])) C}}
{{f[x] ->   c/(2 b)  + E^((Sqrt[b] x)/Sqrt[a]) C + E^(-((Sqrt[b] x)/Sqrt[a])) C}}


# Phase space plot

If we don't want to confine our solution to the positive/negative special case but still get a good idea how our solutions look like, we can instead visualize the solutions with a phase space plot, where we plot the trajectories {f[x], f'[x]}. To do that we first do a simplification, where we replace Abs'[x] by Sign[x]

eq = eulereqs /. Derivative[Abs] -> Sign

(* Out[] *)
2 b f[x] + c Sign[f[x]] - 2 a f''[x] == 0


Through the introduction of helper variable g[x]==f'[x] we can see, that our second order system in f is equivalent to a system of two first order ODEs:

{f'[x]==g[x],
g'[x]==(b/a)f[x] + (c/(2 a)) Sign[f[x]]}


Now to get the correct slope or vector direction of the trajectory in a vector plot we want the rise dg and the run df which we can get as

$$\frac{\text{d}g}{\text{d}f}=\frac{\frac{\text{d}g}{\text{d}x}}{\frac{\text{d}f}{\text{d}x}}=\frac{\frac{b}{a}f+\frac{c}{2a}\text{sign}(f)}{g}$$

and feed that to a VectorPlot or StreamPlot. Let's also use Manipulate to make it interactive and easy to explore the effect of different {a, b, c} parameter values.

Manipulate[
StreamPlot[
{g, b/a f + c/(2 a) Sign[f]}
, {f, -3, 3}, {g, -3, 3}
, FrameLabel -> {"f(x)", "f'(x)"}
]
, {{a, 1}, 0, 5}
, {{b, 2}, -5, 5}
, {{c, 3}, -5, 5}
] To generate a trajectory as function for further computations we can use NDSolveValue like this:

With[{a = 1, b = 2, c = 3},
sol = NDSolveValue[{f''[x] == b/a f[x] + (c/(2a)) Sign[f[x]],
f == 1, f' == 0}, f, {x, -10, 10}];
GraphicsColumn[{
Plot[sol[x], {x, -3, 3}, PlotRange -> All],
ParametricPlot[{sol[x], sol'[x]}, {x, -3, 3}]
}]
]

• Thanks. Just for completeness, do you also know how to solve the concrete optimization problem with fixed initial position and optimizable initial derivative? (I'm mostly interested in the min, not the argmin) For $a=c=1,b=0$, I got $4/3 p_0^{3/2}$ through manual computations; do you get the same? – Bananach Oct 8 at 15:51