2
$\begingroup$

I was working with NDSolve, and suddenly this question, appeared, so I decide to try something:

Define a differential equation:

sole = DSolve[{D[n[x] (x)^4, x] == (n[x])^(1/2), n[1] == 1}, n, x]

Plot the results

Plot[Evaluate[n[x] /. sole], {x, 0.4, 1}]

enter image description here

Now I tried to solve the same differential equation numerically

  sol = NDSolve[{D[n[x] (x)^4, x] == (n[x])^(1/2), n[1] == 1}, n, {x, 0.4, 1}]

Plot the results

  Plot[n[x] /. sol, {x, 0.4, 1}]

enter image description here

Now mathematica gives only one plot

Question

What happened to the other solution?

$\endgroup$
4
  • 1
    $\begingroup$ DSolve appears to be spitting out an unacceptable solution. I believe the blue curve satisfies the differential equation D[n[x] (x)^4, x] == -(n[x])^(1/2), whereas the orange curve satisfies the differential equation D[n[x] (x)^4, x] == (n[x])^(1/2). $\endgroup$
    – march
    Commented Jul 2, 2020 at 17:14
  • $\begingroup$ I think that you are right. However I don't understand why mathematica put a minus sign in this equation D[n[x] (x)^4, x] == -(n[x])^(1/2) $\endgroup$
    – No name
    Commented Jul 2, 2020 at 17:20
  • 1
    $\begingroup$ Mathmatica does some symbolic pre-processing of differential equations, and perhaps there was a mistake in that, or perhaps it doesn't like it when ODE's that don't satisfy the uniqueness theorem show up. I don't know. Note that DSolve[D[n[x] (x)^4, x] == (n[x])^(1/2), n[x], x] yields only one solution. Something about that initial condition is making Mathematica choke. $\endgroup$
    – march
    Commented Jul 2, 2020 at 17:22
  • $\begingroup$ I didn't take in account the uniqueness theorem, so my next question will be really basic: If I take in account the uniqueness theorem, then the differential equation only has 1 solution? $\endgroup$
    – No name
    Commented Jul 2, 2020 at 17:33

1 Answer 1

2
$\begingroup$

Amplifying on comment by @march

Clear["Global`*"]

eqns = {D[n[x] (x)^4, x] == (n[x])^(1/2), n[1] == 1};

sole = DSolve[eqns, n, x]

(* {{n -> Function[{x}, (1 + 2 x + x^2)/(4 x^6)]}, {n -> 
   Function[{x}, (1 - 6 x + 9 x^2)/(4 x^6)]}} *)

Verify the solutions

eqns /. sole // FullSimplify[#, x >= 1/3] &

(* {{False, True}, {True, True}} *)

Only the second solution is valid. This is the solution that matches the numeric result.

In general extraneous solutions are a risk and solutions should be verified.

For numeric results you can check whether the results are "reasonably" close.

sol = NDSolve[eqns, n, {x, 2/5, 1}, WorkingPrecision -> 50][[1]];

Table[(Subtract @@@ eqns) /. sol, {x, 2/5, 1, 1/10}] // N

(* {{-6.2961*10^-29, 0.}, {-2.50343*10^-10, 0.}, {4.90958*10^-9, 
  0.}, {5.45647*10^-9, 0.}, {-3.10546*10^-10, 0.}, {9.492*10^-10, 0.}, {0., 
  0.}} *)
$\endgroup$
4
  • 1
    $\begingroup$ I wonder if this then should be labeled as a bug? $\endgroup$
    – march
    Commented Jul 2, 2020 at 17:23
  • $\begingroup$ Suppose that you have a complicated differential equation, that only can be solved numerically, then, how do you know that the numerical result really is the solution of the differential equation? $\endgroup$
    – No name
    Commented Jul 2, 2020 at 17:27
  • $\begingroup$ I'm sorry I don't understand what do you mean with "reasonably" close. Can you explain a little bit more? $\endgroup$
    – No name
    Commented Jul 4, 2020 at 21:02
  • 1
    $\begingroup$ @Cruz - for any equation Abs[LHS-RHS] should evaluate to zero. For a numerical solution there will generally be a non-zero value. What small value is acceptable will depend on the problem. Whatever threshold is deemed acceptable is what defines reasonably close. $\endgroup$
    – Bob Hanlon
    Commented Jul 4, 2020 at 21:35

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.