2

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.

  • 1
    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. – bbgodfrey Apr 19 '20 at 00:41

1 Answers1

4

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

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
  • 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 ? – Hoang Nguyen Apr 19 '20 at 00:37
  • NMinimize returns {0., {bc2 -> 1.}}. [-1,-1,-1] extracts .1. See the documentation for Part. – bbgodfrey Apr 19 '20 at 00:47
  • @bbgodfrey (+1) What is the reason for NMinimize in this code? It looks like method "Shooting" getting solution it self. – Alex Trounev Apr 19 '20 at 11:45
  • @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. – bbgodfrey Apr 19 '20 at 12:03
  • @bbgodfrey (+1) from me. – Hoang Nguyen Apr 19 '20 at 12:26
  • @bbgodfrey In what kind of BVP it could work? – Alex Trounev Apr 19 '20 at 12:57
  • @AlexTrounev Perhaps, the OP had in mind a more complicated expression for bc2 than (bc2 - 1)^2. In any case, I wished to provide a solution using code that differed as little as possible from that in the question. – bbgodfrey Apr 19 '20 at 13:01