0

So I have a 'fairly simple' problem that needs to be 'solved'. I have been able to solve this running 2 loops in Matlab but I am sure Mathematica should be able to handle this. I have the ODE $$F'(x)+\sqrt{a^3 x F(x)}=0$$ subject to the boundary conditions $$F(0)=\dfrac{1}{a} \quad \text{and} \quad F(1)=0.$$ To complicate the problem, $a$ must satify the condition $$\dfrac{1}{a}=2\int_0^1 F dx.$$

First I tried using With to try 'correct' for the unknown value of $a$

eq = F'[x] + Sqrt[ a^3 x F[x]] == 0;
eps = 10^(-6);
With[{a = 2 NIntegrate[F[x], {x, eps, 1}]}, 
  sol = NDSolve[{eq, F[eps] == 1/a}, F, {x, eps, 1}]];

I used eps to avoid any issues at 0. Naturally this approach caused many errors as $a$ was defined using something that hadn't been calculated yet. So I don't even know if this is possible.

My second thought was to use ParametricNDSolveValue but I don't know if it's possible to integrate a parametric numerical solution. Maybe I should take a path similar to here?

Any advice would be greatly appreciated

Kendall
  • 363
  • 1
  • 10

2 Answers2

2

Let DSolve do the job.

eq = F'[x] + Sqrt[ a^3 x F[x]] == 0; 

dsol = DSolve[{eq, F[1] == 0}, F, x]

(*   {{F -> Function[{x}, 1/9 (a^3 - 2 a^3 x^(3/2) + a^3 x^3)]}}   *)

sol = Solve[1/a == 2 Integrate[F[x] /. First@dsol, {x, 0, 1}], a, Reals]

(*   {{a -> -10^(1/4)}, {a -> 10^(1/4)}}   *)

Fsol[x_] = F[x] /. First@dsol /. sol[[2]] // FullSimplify

(*   1/9 10^(3/4) (-1 + x^(3/2))^2   *)

But you get contradiction with initial conditions:

Fsol[0] == 1/a /. sol

(*   {False, False}   *)
Akku14
  • 17,287
  • 14
  • 32
  • Thank you for this answer. I know an analytic solution to this equation exists, that's why I chose it. What I am aiming for, is a numerical solution using a shooting method so I can compare the numerical solution to the analytic one. I was able to do this in matlab but I would like to see if Mathematica can solve it faster.

    I also realised that initial condition is false. I think it's a typo in the BC's that were given.

    – Kendall Jan 19 '20 at 11:45
  • That BC is an initial guess for the shooting method. – Kendall Jan 19 '20 at 11:58
0

This problem was solved, faster, outside of Mathematica using a FVP RK4 method. I am unaware if such a method has been inbuilt/implemented into NDSolve. If it has been, then the accuracy and duration to calculate such an answer is neither trivial nor fast. This answer serves to close the question.

Kendall
  • 363
  • 1
  • 10