# "Ambiguity, should literally match independent variables" in NDSolve with shooting method

there. I am trying to solve a seccond order equation, with 1 boundary condition at the start of the range and another at the end of the range. I've attempted to reduce my problem so that it is non-trivial but still retains the error. Consider the following code:

NDSolve[{M''[x] == -(M[x]/(-x - (M[0])^2)), M'[0] == -(1/M[0]) 0.5 ,
M[1] == 1}, M, {x, 0, 1},
Method -> {"Shooting", "StartingInitialConditions" -> {M[0] == 0.1}}]


There is the correct number of boundary conditions present and the initial guess does not seem like it should cause an infinities. As far as I can see all of the variables match. I did chop away part of this equation so its possible there is no solution but I suspect if that were the case it would give a different error. The current error this gives me is NDSolve::litarg:

I am able to remove this error by replacing M[0] that appears inside of the differential equation definition with a scalar value, e.g 3. However, I don't think I can remove this term. Any suggestions would be welcome.

You can also use a dummy variable with derivative equal to zero:

sol = NDSolve[{M''[x] == -(M[x]/(-x - (k[x])^2)),
k'[x] == 0, k[0] == M[0],
M'[0] == -(1/M[0]) 0.5, M[1] == 1}, M, {x, 0, 1},
Method -> {"Shooting",
"StartingInitialConditions" -> {M[0] == 0.1}}];
ListLinePlot[M /. sol]


• Thank you so much Michael! I was so close to trying this idea but gave up for the day! This should definately. Dec 3 '21 at 1:25
• @MichaelE2 This is very nice solution (+1). Dec 3 '21 at 1:38

This parametric equation can be solved as follows

m =
ParametricNDSolveValue[{M''[x] == -(M[x]/(-x - p^2)),
M'[0] == -(1/p) 0.5, M[1] == 1}, M, {x, 0, 1}, {p}]

sol = FindRoot[m[p][0] == p, {p, 1/10}]

(*Out[]= {p -> 1.11403}*)

Plot[m[p][x] /. sol, {x, 0, 1}]


• Thanks so much Alex! I havent used this function but i think this should work in the unsimplified case too i just have to check tomorrow. Thanks for the awesome response! Dec 3 '21 at 1:26
• Thank you! Please, pay attention that in current version NDSolve we can't use boundary condition in differential equation directly, but only as parameter. Also Michael shows very nice solution. Dec 3 '21 at 1:40