20
$\begingroup$

Bug introduced in 12.0.0


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$
  • 2
    $\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 May 2 at 12:35
  • $\begingroup$ Can't reproduce in v9.0.1 and v11.2. Which version are you in? $\endgroup$ – xzczd May 2 at 12:36
  • 1
    $\begingroup$ @xzczd 12.0.0.0 $\endgroup$ – Siwei May 2 at 12:37
  • 2
    $\begingroup$ Please report it to Wolfram: support.wolfram.com $\endgroup$ – Szabolcs May 2 at 12:58
  • 2
    $\begingroup$ @Superfrankie: Interestingly, wolframalpha.com/input/… $\endgroup$ – Moo May 2 at 13:09
10
$\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$
  • 2
    $\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 May 2 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 May 2 at 21:01
  • $\begingroup$ Are there other known consequences of this Series bug? $\endgroup$ – Slepecky Mamut May 13 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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.