I am trying to solve a system of two Euler equations with a constraint. I do not know the initial conditions and I thought to use ParametricNDSolve to solve the equations and find the parameters that solve the constraint. Here is my code:

rs[r_] = (3/(4 Pi u[r]^2))^(1/3);
A = (Log[2] - 1)/(2 Pi^2);
b = 20.4562557;
rin = 10^-10;
L = 2.87 u[r]^(10/3) r^2 + 1/18 u'[r]^2 r^2 + (-3/4 (3/Pi)^(1/3) u[r]^(2/3) + A Log[b/rs[r] + b/rs[r]^2 + 1]) r^2 u[r]^2 - 1/(8 Pi) r^2 \[Phi]'[r]^2 + (u[r]^2 + 79 DiracDelta[r]) \[Phi][
     r] r^2;
eqn1 = EulerEquations[L, u[r], r];
eqn2 = EulerEquations[L, \[Phi][r], r];
sol = ParametricNDSolve[{eqn1, eqn2, u[rin] == a, \[Phi][rin] == e, 
   u'[rin] == c, \[Phi]'[rin] == d}, {u, \[Phi]}, {r, rin, 1}, {a, e, 
   c, d}]
U[r_] := u[r] /. sol[[1]]
FindMinimum[Integrate[U[r]^2 r^2, {r, rin, 1}] == 79, {a, c,d,e}]

I get the errors:

"Too many parameters in {a,e,c,d} to be filled from {1/10000000000+IntegrateImproperDumpnewx}"

The integrand r^2 \ParametricFunction[1,<<12>>[<<1>>],<<3>>,{NDSolvebase$22542,NDSolve\ NDSolveParametricFunction[0,{ParametricNDSolve,Internal`Bag[<2>],None}\ ,<<6>>,{},All]}][r]^2 has evaluated to non-numerical values for all \ sampling points in the region with boundaries {{1/10000000000,1}}

What do they mean? How can I solve my system of equations?

  • $\begingroup$ We get a different error. $\endgroup$
    – user21
    Apr 15, 2020 at 12:07
  • $\begingroup$ Which error? I am running Mathematica 10.0 if needed. @user21 $\endgroup$
    – mattiav27
    Apr 15, 2020 at 12:08
  • $\begingroup$ do u[r], \[Phi][r] have a definition attached to them? $\endgroup$ Apr 15, 2020 at 12:17
  • $\begingroup$ @yosimitsukodanuri I have just re-run the code after a ClearAll["Global*"]`, but nothing has changed $\endgroup$
    – mattiav27
    Apr 15, 2020 at 12:19
  • 1
    $\begingroup$ Open a new empty notebook. Quit the kernel and copy the code form your post and you will get a different error. $\endgroup$
    – user21
    Apr 15, 2020 at 13:27

2 Answers 2


Define rs and L with SetDelayed. Similarly use delayed definitions for eqn1 and eqn2 eg eqn1[r_] := Evaluate[EulerEquations[L[r], u[r], r]]. After doing so and evaluating ParametricNDSolve, sol should contain the parametric solutions for u and φ which should look like this:

enter image description here

Next, use Set to define U as in U = u /. sol[[1]]; now U is equal to the parametric solution obtained in the previous step.

The integrand function and the objective function need their own definitions:

integrand[U_, r_] := U[r]^2 r^2
objective[U_,a_, c_, d_, e_] := NIntegrate[integrand[U[a, c, d, e], r], {r, rin, 1}] - 79

Now, at this point if you experiment a bit with what you've got eg. with something like

RandomReal[{rin, 1}, {100, 4}] // (Apply[Quiet[Check[objective[U, ##], $Failed]] &, #, 1] &) /* (GatherBy[#, FailureQ] &)

what you get is a fair amount of $Failed and some more really big numbers. These two observations together seem to imply to me that there's some sort of a convergence problem with the integral, but don't take my word for it, I could be wrong.

Now, moving on along with the optimization part: after evaluating

FindMinimum[objective[U, a, c, d, e] == 0, {a, c, d, e}]

we get tons of error messages about NIntegrate::inumr followed by some NIntegrate::ncvb ones; the former are about non-numeric values while the later are about non-convergence.

If I'd had to guess I'd say that the parametric function is undefined for some values of the params a fact which produces the first type of errors while the convergence issue alluded to above is probably responsible for the later messages.

Hope this helps to get some attention on the Q. and have someone that knows better than me what's going on to give a solid response. Sorry I couldn't be more helpful.

  • 1
    $\begingroup$ Thanks for the help $\endgroup$
    – mattiav27
    Apr 15, 2020 at 13:40

As a partial answer to my question, after experimenting a bit and reading carefully the documentation for ParametricNDSolve, I have arrived to the conclusion that the definition of U[r]is wrong. The correct definition is:

U[a_, c_, d_, f_][r_] := u[a, c, d, f][r] /. {sol[[1]]};

After this I can integrate numerically:

4 Pi NIntegrate[U[10^4, 10^4, 10^4, 10^4][r]^2 r^2, {r, rin, rout}]

I still get the error:

The integrand r^2 \ ParametricFunction[1,<<4>>,{NDSolvebase$195049,NDSolve\ NDSolveParametricFunction[0,{ParametricNDSolve,Internal`Bag[<2>],None}\ ,<<6>>,{},All]}][a,c,d,f][r]^2 has evaluated to non-numerical values \ for all sampling points in the region with \ boundaries {{1/100000000000000000000,27/200000000000}}

when using FindMinimum as before.


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.