I'd like to use NDSolve and to make a constraint with an integral.
For example, take the very simple : $$f'(x)=-f(x)/x_0 $$ the solution is $$f(x)=f_0 e^{-x/x_0} $$
And $f_0$ is given by : $$\int_0^{+\infty} f(x)dx=F\implies f_0 = F/x_0 $$
Now let's make it a bit more complicated :
$$f'(x)(1+Df(x)(1-f(x))f(x)^2) =-f(x)/x_0$$
let's assume : $D=20,x_0=1$.
One can solve this equation using boundary conditions :
f[x_] = f[x] /.
NDSolve[{f'[x] (1 + 20 f[x] (1 - f[x]) f[x]^2) == -f[x],
f[0] == 0.6}, f, {x, 0, 5}];
Plot[f[x], {x, 0, 5}]
But I'd like to solve it using the condition : $\int_0^5f(x)dx=1.2$ for example.
How can I do ?
What I imagined is something like that :
F = 1.2;
f[x_, a_] :=
f[x] /. NDSolve[{f'[x] (1 + 20 f[x] (1 - f[x]) f[x]^2) == -f[x],
f[0] == a}, f, {x, 0, 5}][[1]];
M[a_] := (NIntegrate[f[x, a], {x, 0, 5}] - F)^2
sol = NMinimize[{M[a], 0 < a < 1}, a]
But I'm getting errors :
NDSolve::ndinnt: Initial condition a is not a number or a rectangular array of numbers.