21
$\begingroup$

Bug introduced in 12.0.0, fixed in 12.1.1.


I was trying to solve the following differential equation: $$\frac{dy}{dx}=x^2+y^2-1 \quad \text{and} \quad y(0)=1$$

and I used the code below:

DSolve[{y'[x] == y[x]^2 + x^2 - 1, y[0] == 1}, y[x], x]

The output from Mathematica 12 is

{{y[x] -> 1/(1 - x)}}

However, it is obviously wrong because if $y(x)=\dfrac{1}{1-x}$, then $$y'(x)=\dfrac{1}{(1-x)^2} \neq \left(\dfrac{1}{1-x}\right)^2+x^2-1$$

I cannot figure out why.

$\endgroup$
7
  • 3
    $\begingroup$ Looks like a bug to me (in V12.0). Also fails on the ode: DSolve[{y'[x] == y[x]^2 + x^2 - 1}, y, x] $\endgroup$
    – Michael E2
    Commented May 2, 2019 at 12:35
  • $\begingroup$ Can't reproduce in v9.0.1 and v11.2. Which version are you in? $\endgroup$
    – xzczd
    Commented May 2, 2019 at 12:36
  • 1
    $\begingroup$ @xzczd 12.0.0.0 $\endgroup$
    – Siwei Feng
    Commented May 2, 2019 at 12:37
  • 2
    $\begingroup$ Please report it to Wolfram: support.wolfram.com $\endgroup$
    – Szabolcs
    Commented May 2, 2019 at 12:58
  • 2
    $\begingroup$ @Superfrankie: Interestingly, wolframalpha.com/input/… $\endgroup$
    – Moo
    Commented May 2, 2019 at 13:09

3 Answers 3

13
$\begingroup$

As noted by other users, this is a bug in DSolve in Version 12.0.

The problem appears to be related to a change in Series between Version 11.3 and Version 12.0, which is under investigation.

A partial workaround for the problem is to set an assumption on the independent variable as shown below to obtain the correct solution.

In[1]:= DSolve[{y'[x] == y[x]^2 + x^2 - 1, y[0] == 1}, y[x], x, 
  Assumptions -> x > 0] // InputForm

Out[1]//InputForm=
{{y[x] -> (I*2^(I/2)*x*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 + I/4]*
      ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] + (1 - I)*2^(1/2 + I/2)*x*Gamma[1/4 + I/4]*
      Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] + 
     I*x*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 - I/4]*ParabolicCylinderD[-1/2 + I/2, 
       (1 + I)*x] + (1 + I)*Sqrt[2]*x*Gamma[1/4 - I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
      ParabolicCylinderD[-1/2 + I/2, (1 + I)*x] - (1 - I)*2^(I/2)*Gamma[1/4 - I/4]*
      Gamma[1/4 + I/4]*Gamma[3/4 + I/4]*ParabolicCylinderD[1/2 - I/2, (-1 + I)*x] + 
     2^(3/2 + I/2)*Gamma[1/4 + I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
      ParabolicCylinderD[1/2 - I/2, (-1 + I)*x] - (1 + I)*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*
      Gamma[3/4 - I/4]*ParabolicCylinderD[1/2 + I/2, (1 + I)*x] - 
     2*Sqrt[2]*Gamma[1/4 - I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
      ParabolicCylinderD[1/2 + I/2, (1 + I)*x])/
    (2^(I/2)*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 + I/4]*
      ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] - (1 + I)*2^(1/2 + I/2)*Gamma[1/4 + I/4]*
      Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] - 
     Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 - I/4]*ParabolicCylinderD[-1/2 + I/2, 
       (1 + I)*x] - (1 - I)*Sqrt[2]*Gamma[1/4 - I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
      ParabolicCylinderD[-1/2 + I/2, (1 + I)*x])}}

I apologize for the confusion caused by this issue.

Devendra Kapadia, Wolfram Research, Inc.

$\endgroup$
3
  • 3
    $\begingroup$ Unfortunately, this does not work under the assumption $x<0$ though the solution is valid (at least, for small negative values of $x$). $\endgroup$
    – user64494
    Commented May 2, 2019 at 19:22
  • 1
    $\begingroup$ @user64494 It's because the series is being expanded about (positive) Infinity. The assumption x < 0 would contradict that and cause Series to fail. $\endgroup$
    – Michael E2
    Commented May 2, 2019 at 21:01
  • $\begingroup$ Are there other known consequences of this Series bug? $\endgroup$ Commented May 13, 2019 at 12:18
11
$\begingroup$

Here's a workaround for this particular case, based on the method shown in Riccati Equation:

Block[{DSolve`DSolveFirstOrderODEDump`Riccati},
 DSolve`DSolveFirstOrderODEDump`Riccati[y_[x_], q0_, q1_, q2_, c_] :=
  Module[{R, S, u},
   S = q2*q0;
   R = q1 + D[q2, x]/q2;
   {{y[x] -> -u'[x]/(q2*u[x]) /. 
       First@DSolve[u''[x] - R*u'[x] + S*u[x] == 0, u, x] /. {C[2] -> 
        C[1] c, C[1] -> c}}}
   ];
 sol = DSolve[ivp = {y'[x] == y[x]^2 + x^2 - 1, y[0] == 1}, y, x]
 ]

Mathematica graphics

ivp /. sol // FullSimplify
(*  {{True, True}}  *)
$\endgroup$
4
$\begingroup$

This seems to be fixed in 12.1.1, DSolve and DSolveValue give the same result as in the workarounds posted:

screenshot of notebook

$\endgroup$

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.