5
$\begingroup$

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:

enter image description here

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.

$\endgroup$

2 Answers 2

8
$\begingroup$

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]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you so much Michael! I was so close to trying this idea but gave up for the day! This should definately. $\endgroup$
    – akozi
    Dec 3, 2021 at 1:25
  • 1
    $\begingroup$ @MichaelE2 This is very nice solution (+1). $\endgroup$ Dec 3, 2021 at 1:38
5
$\begingroup$

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}]

Figure 1

$\endgroup$
2
  • $\begingroup$ 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! $\endgroup$
    – akozi
    Dec 3, 2021 at 1:26
  • 1
    $\begingroup$ 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. $\endgroup$ Dec 3, 2021 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.