Need help with ODE producing error ParametricNDSolve::dsvar: [closed]

The function below is a function of the independent variable a with parameter n0. My goal is to get numerical value for n0. When I run the code, it produces the message

ParametricNDSolve::dsvar: 23 cannot be used as a variable.

Would anyone please help me to evaluate n0?

b = 649286441/466126265;
ϵ = $MachineEpsilon; ps = ParametricNDSolveValue[ {x''[a] + 2 x'[a] == -(357/11500) n0 Exp[x[a]], x[ϵ] == x0, x'[ϵ] == 0, WhenEvent[a == 1, x'[a] -> x'[a] + 714/23]}, {x, x'}, {a, ϵ, b}, {n0}, Method -> "StiffnessSwitching", WorkingPrecision -> 30]; sol = FindRoot[Last[ps[x0]][b], {x0, -10.7, 0}, Evaluated -> False][[1, 2]]  closed as off-topic by Johu, m_goldberg, J. M. will be back soon♦Sep 26 '18 at 13:43 This question appears to be off-topic. The users who voted to close gave this specific reason: • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Johu, m_goldberg, J. M. will be back soon If this question can be reworded to fit the rules in the help center, please edit the question. • the lines starting with s =.. is missing closing } and ]. – kglr Sep 21 '18 at 15:58 • Thanks I fixed but still I can not get n0. – user60302 Sep 21 '18 at 16:01 • What problem do you solve? Your code contains a lot of errors. To fix them, one must at least know the statement of the problem. – Alex Trounev Sep 21 '18 at 16:15 • Exp[-x][a] should be Exp[-x[a]]. And please provide the values for \[Epsilon], ri and x0. – kglr Sep 21 '18 at 16:16 • ... also, replace of 3.14 with Rationalize[3.14, 0]. – kglr Sep 21 '18 at 16:22 2 Answers b = 649286441/466126265; ϵ =$MachineEpsilon;
ps =
ParametricNDSolveValue[
{x''[a] + 2 x'[a] == -(357/11500) n0 Exp[x[a]],
x[ϵ] == x0, x'[ϵ] == 0,
WhenEvent[a == 1, x'[a] :> (x'[a] + 714/23)]},
{x, x'}, {a, ϵ, b}, {n0},
Method -> "StiffnessSwitching",
WorkingPrecision -> 30]


Note change made to WhenEvent expression.

• Great! What is the value of n0? – user60302 Sep 21 '18 at 18:23
• @user60302. The parameter n0 has no value because you told ParametricNDSolveValue it was a free parameter. To get an actual solution from your oarametric family of ODEs you must assign a value to both n0 and x0. You cannot solve for n0. – m_goldberg Sep 21 '18 at 20:03
• @user60302. As I see it, ParametricNDSolveValue returns a solver not a solution in the normal sense. When the solver is given values for the free parameters, it then solves the ODE numerically for a specific solution and returns that solution in the form of an interpolating function. That's why you can't solve for a parameter. – m_goldberg Sep 21 '18 at 20:15

The author did not formulate the problem. From the discussion it became clear that we must find n0, under the conditions that x0 is also unknown, but can be determined in the course of the solution. This task, apparently, does not have a single solution. I will point out one of the solutions

b = 649286441/466126265;
\[Epsilon] = 0100;
xn = -10.3937674129241835084215988486799043382603309698646666546193100.;
ps = ParametricNDSolveValue[{x''[a] +
2 x'[a] == -(357/11500) n0 Exp[x[a]], x[\[Epsilon]] == x0,
x'[\[Epsilon]] == 0, WhenEvent[a == 1, x'[a] -> (x'[a] + 714/23)]},
x', {a, \[Epsilon], b}, {n0, x0}, Method -> "StiffnessSwitching",
WorkingPrecision -> 100]
FindRoot[ps[n0, xn][b], {n0, 99356}, WorkingPrecision -> 100]


Even with these parameters, the solution does not converge. I will indicate only the approximate result

nm = 99355.5496428760234772215566854011786969761748970188973887906416640553735266314087677155869333265407520963532767501108239100.;


We compute the function at these points

ps[nm, xn][b]

Out[]= 1.613498769806814501841157873656834618862053484217197348048863157358103610167513466653510372*10^-7


We display this solution

Finally, we show the function x[a]

xs = ParametricNDSolveValue[{x''[a] +
2 x'[a] == -(357/11500) n0 Exp[x[a]], x[\[Epsilon]] == x0,
x'[\[Epsilon]] == 0, WhenEvent[a == 1, x'[a] -> (x'[a] + 714/23)]},
x, {a, \[Epsilon], b}, {n0, x0}, Method -> "StiffnessSwitching",
WorkingPrecision -> 30]

Plot[xs[nm, xn][a], {a, \[Epsilon], b}]
`