2

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?

No name
  • 585
  • 1
  • 5
  • 17
  • 1
    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). – march Jul 02 '20 at 17:14
  • 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) – No name Jul 02 '20 at 17:20
  • 1
    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. – march Jul 02 '20 at 17:22
  • 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? – No name Jul 02 '20 at 17:33

1 Answers1

2

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.296110^-29, 0.}, {-2.5034310^-10, 0.}, {4.9095810^-9, 0.}, {5.4564710^-9, 0.}, {-3.1054610^-10, 0.}, {9.49210^-10, 0.}, {0., 0.}} *)

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 1
    I wonder if this then should be labeled as a bug? – march Jul 02 '20 at 17:23
  • 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? – No name Jul 02 '20 at 17:27
  • I'm sorry I don't understand what do you mean with "reasonably" close. Can you explain a little bit more? – No name Jul 04 '20 at 21:02
  • 1
    @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. – Bob Hanlon Jul 04 '20 at 21:35