2
$\begingroup$

I am trying to solve this differential equation but using my approach:

sol2[bc2_] := NDSolveValue[{χ''[x] == (χ^3/2)/Sqrt[x], χ[0] == bc2, χ[10] == 0},
χ, {x, 0, 10}];
χ2 = sol2[NMinimize[(bc2 - 1)^2, bc2][[-1, -1, -1]], {0, 1}]
Plot[{χ2[x]}, {x, 0, 10}]

I got a wrong result enter image description here

How can I implement my method correctly ? Thank you.

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Commented Apr 19, 2020 at 0:41

1 Answer 1

4
$\begingroup$

The code contains a few minor errors:

  • The computation must start a tiny distance fromx = 0, because the ODE is singular there. (I used x0 = 10^-8 but verified that the solution was insensitive to small changes.)
  • Replace χ^3/2 by χ[x]^3/2 in the ODE.
  • Delete , {0, 1} from second equation.

However, the main issue is that the solution is strongly dependent on the choice of χ2'[x] near x == 0. Hence, the Shooting option must be employed explicitly, and a good guess given.

x0 = 10^-8;
sol2[bc2_] := NDSolveValue[{χ''[x] == (χ[x]^3/2)/Sqrt[x], χ[x0] == bc2, χ[10] == 0},
  χ, {x, x0, 10}, Method -> {"Shooting", "StartingInitialConditions" -> {χ'[x0] == -.85}}]
χ2 = sol2[NMinimize[(bc2 - 1)^2, bc2][[-1, -1, -1]]];
Plot[{χ2[x]}, {x, x0, 10}]

I obtained the guess for χ'[x0] == -.85 by experimentation.

enter image description here

$\endgroup$
7
  • $\begingroup$ Thank you very much for an elegant solution. In my code for the NMinimize[(bc2 - 1)^2, bc2][[-1, -1, -1]], I don't know what is the purpose of [-1,-1,-1] ? Can you elaborate on that option ? $\endgroup$ Commented Apr 19, 2020 at 0:37
  • $\begingroup$ NMinimize returns {0., {bc2 -> 1.}}. ` [-1,-1,-1]` extracts .1. See the documentation for Part. $\endgroup$
    – bbgodfrey
    Commented Apr 19, 2020 at 0:47
  • $\begingroup$ @bbgodfrey (+1) What is the reason for NMinimize in this code? It looks like method "Shooting" getting solution it self. $\endgroup$ Commented Apr 19, 2020 at 11:45
  • $\begingroup$ @AlexTrounev You are correct that NMinimize serves no substantive purpose in the answer. I retained it from the question, because I assumed that the OP planned to apply the code to a more challenging problem. $\endgroup$
    – bbgodfrey
    Commented Apr 19, 2020 at 12:03
  • $\begingroup$ @bbgodfrey (+1) from me. $\endgroup$ Commented Apr 19, 2020 at 12:26

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.