4
$\begingroup$

This is first order homogeneous ode from undergraduate textbook, which can be solved using standard $y=u x$ change of variables. But DSolve can't. Could someone figure out why? I show below that using Mathematica's DSolveChangeVariables it gives the correct solution.

ClearAll[y, u, x]
ode1 = (x^2 + 2*x*y[x] - y[x]^2) + (y[x]^2 + 2*x*y[x] - x^2)*y'[x] == 0;
ic1 = y[1] == -1;
DSolve[{ode1, ic1}, y[x], x]

enter image description here

But the solution is $y=-x$, Here is Maple's solutions

ode:=(x^2+2*x*y(x)-y(x)^2)+(y(x)^2+2*x*y(x)-x^2)*diff(y(x),x)=0;
ic:=y(1)=-1;
dsolve([ode,ic])

enter image description here

It is possible to get this solution using Mathematica using change of variable (standard method) of $y=u x$

solU=DSolveChangeVariables[Inactive[DSolve][{ode1,ic1},y[x],x],u,x,y[x]==u[x]*x]
solu=Activate[solU]
sol = y[x] == u[x]*x /. solu

Gives

{y[x] == -x}

So why did DSolve not solve it?

I tried Wolfram Alpha to see the steps to see where it fails, but it also could not solve it.

I am sure the problem it had is with solving for the constant of integration as DSolve can solve it without IC

ClearAll[y, u, x]
ode1 = (x^2 + 2*x*y[x] - y[x]^2) + (y[x]^2 + 2*x*y[x] - x^2)*y'[x] ==  0;
ic1 = y[1] == -1;
DSolve[ode1, y[x], x]

enter image description here

Why Mathematica could not solve for $c_1$ from the initial conditions? Could someone help Mathematica's solve for the constant $c_1$ from the above solution given the initial conditions?

V 14 on windows.

$\endgroup$
2
  • $\begingroup$ If I try to Solve any of your solutions without the IC I get an empty set... $\endgroup$
    – mattiav27
    Commented Jun 17 at 9:37
  • $\begingroup$ However FindRoot finds a solution for your first solution approximately at 19.6205. It seems a problem with Solve. I use version 13.0 for Linux. $\endgroup$
    – mattiav27
    Commented Jun 17 at 9:41

3 Answers 3

2
$\begingroup$

Your first solution tends to y==-x asymptotically for c1->Infinity

Asymptotic[1/2 (E^c1 - Sqrt[E^(2 c1) + 4 E^c1 x - 4 x^2]), c1 -> Infinity, Assumptions -> Element[x, Reals]] 
(*-x*)
$\endgroup$
3
  • $\begingroup$ Yes, that is correct. Strange that Mathematica did not do the limit when it found that $c_1$ is infinity at IC. But it was able to do it for the transformed ODE. $\endgroup$
    – Nasser
    Commented Jun 17 at 11:17
  • $\begingroup$ Yes, that is strange. Mathematica isn't able to solve Solve[{-((-1 + Sqrt[1 + 4 eps - 4 eps^2])/(2 eps)) == -1 }, eps] (* {} *) even though Asymptotic[ -((-1 + Sqrt[1 + 4 eps - 4 eps^2])/(2 eps)) + 1 , eps -> 0] (* 2 eps *) $\endgroup$ Commented Jun 17 at 11:58
  • $\begingroup$ fyi, the Limit command will also work instead of Asymptotic $\endgroup$
    – Nasser
    Commented Jun 18 at 0:38
6
$\begingroup$
DSolve[{ode1, ic1}, y[x], x, IncludeSingularSolutions -> True, 
 Assumptions -> x \[Element] Reals]

< several DSolve::bvnul messages >

(*  {{y[x] -> -x}}  *)

Pro tip: Solution suggested by

Trace[
   DSolve[{ode1, ic1}, y[x], x, IncludeSingularSolutions -> True],
   lim_Limit :> HoldForm[lim] -> lim,
   TraceInternal -> True
   ] // Flatten // Column[#, Dividers -> {False, All}] &

The condition on the limit that yields -x indicates why DSolve cannot handle the problem without assumptions. One infers it rejects conditional solutions. One might suggest to WRI that they reconsider that design choice. It's not clear that the condition is necessary. It seems unnecessary to me if C[1] is approaching real plus-infinity, but maybe I'm making a mistake.

Here's general solution including singular solutions under the assumption:

DSolve[{ode1}, y[x], x, IncludeSingularSolutions -> True, 
 Assumptions -> x \[Element] Reals]
(*
{{y[x] -> 1/2  (E^C[1] - Sqrt[E^(2  C[1]) + 4 E^C[1] x - 4 x^2])},
 {y[x] -> 1/2  (E^C[1] + Sqrt[E^(2  C[1]) + 4 E^C[1] x - 4 x^2])},
 {y[x] -> -x},
 {y[x] -> -I  Abs[x]},
 {y[x] -> I Abs[x]}}
*)

Addendum: Following @Nasser's hint (reference Q&A)

Internal`InheritedBlock[{DSolve`DSolveParser},
 Unprotect@DSolve`DSolveParser;
 DownValues@DSolve`DSolveParser = 
  Prepend[DownValues@DSolve`DSolveParser,
   HoldPattern[
     DSolve`DSolveParser[stuff__, {C, rest__}] /; ! TrueQ[$in]] :> 
    Block[{$in = True},
     DSolve`DSolveParser[stuff, {Log@*C, rest}]
     ]
   ];
 Protect@DSolve`DSolveParser;
 
 DSolve[{ode1, ic1}, y[x], x, IncludeSingularSolutions -> True, 
  GeneratedParameters -> Log@*C]
 ]

DSolve::bvnul: For some branches of the general solution, the given boundary conditions lead to an empty solution.

DSolve::bvnul: For some branches of the general solution, the given boundary conditions lead to an empty solution.

DSolve::bvnr: For some branches of the general solution, the given boundary conditions do not restrict the existing freedom in the general solution.

(*  {{y[x] -> -x}}  *)
$\endgroup$
3
  • $\begingroup$ btw, if Mathematica changes all those $e^{c_1}$ to just $c_1$, then no need for assumptions that $x$ is real. i,e, this works Limit[1/2 (C[1] - Sqrt[C[1]^2 + 4 C[1] x - 4 x^2]), C[1] -> Infinity] gives $-x$. We talked before about this and why Mathematica does not like to change $e^{c_1}$ to just $c_1$ like we do when solving this by hand. You also wrote a function which converts all these. I will try to find that post with your function in it :) $\endgroup$
    – Nasser
    Commented Jun 18 at 0:42
  • $\begingroup$ Here is link to your answer which changes all those $e^{c_1}$ that show up in solution to $c_1$ as needed. If you can figure how to enject your code into DSolve operation, then it might now be able to solve the ode ! $\endgroup$
    – Nasser
    Commented Jun 18 at 0:44
  • 1
    $\begingroup$ @Nasser Thanks. See update. GeneratedParameters -> Log@*C works for the general solution, but the limits are computed before the parameters are rewritten. Thus I had to hack an internal function. Oddly, the internal hack works on the general solution (without the IC), but to get the singular solution, both the hack and GeneratedParameters -> Log @* C are needed. $\endgroup$
    – Michael E2
    Commented Jun 18 at 3:41
1
$\begingroup$

y=-x is the singular solution of the ode. According to the documentation, adding the option IncludeSingularSolutions -> True to DSolve should return the special solution, like

sol = DSolve[ode1, y[x], x, GeneratedParameters -> (k &), 
  IncludeSingularSolutions -> True]

{{y[x] -> 1/2 (E^k - Sqrt[E^(2 k) + 4 E^k x - 4 x^2])}, {y[x] -> 1/2 (E^k + Sqrt[E^(2 k) + 4 E^k x - 4 x^2])}}

Unfortunately, the solution y=-x is not included. I'm wondering if it is a bug. The plot shows that the asymptote of the first set of solutions is y=-x:

Plot[Table[sol[[1, 1, 2]], {k, 0, 10}] // Evaluate, {x, 0, 30}, 
 AspectRatio -> Automatic]

enter image description here

$\endgroup$
4
  • $\begingroup$ You did not include the IC in DSolve. What happens if you add it? $\endgroup$
    – mattiav27
    Commented Jun 17 at 13:10
  • $\begingroup$ @mattiav27 Nothing will happen. $\endgroup$
    – Jie Zhu
    Commented Jun 17 at 13:23
  • $\begingroup$ btw, Mathematica have very loose definition of singular solution. Singular solutions for first order ode do not exist if the derivative $y'(x)$ is linear. But Mathematica still generate such solutions even though these can be obtained from the general solution for some values of the constant of integration, which real singular solutions can not. Mathematica calls these "equilibrium" solutions in help page. So these are not really singular solutions in true sense since $y'$ is linear in the ode. The methods to find true singular solutions is called p-discriminant and c-discriminant. $\endgroup$
    – Nasser
    Commented Jun 18 at 0:50
  • $\begingroup$ These are envelop of general solution. Here are some examples on this page $\endgroup$
    – Nasser
    Commented Jun 18 at 0:51

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.