Bug introduced in 10.0.0 and fixed in 10.0.2
Clear[y,x];
DSolve[D[y[x], x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0, y[x], x,
GeneratedParameters -> C]
or
DSolve[D[y[x], x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0, y[x], x]
both return a solution that does not include C[1]
, the constant of integration.
{{y[x] -> Sin[x]}}
The question is: Should DSolve
always return an arbitrary constant? Even though the answer is correct, it is missing C[1]
hence this is a particular solution.
If DSolve
does not have to generate a constant of integration in the solution of a differential equation, then what caused it not to generate it in this specific case?
Update:
Let me add a solution found by Maple for this, which does include a constant of integration:
Clear[C,y,x];
eq = Derivative[1][y][x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0;
eq /. y -> (- Exp[-Cos[#]]/(C[1] + Integrate[ Exp[-Cos[#]], x]) + Sin[#] &);
Simplify[%]
(* True *)
So, the above is a general solution with a constant of integration that solves the same differential equation.
Answer
I think it's a bug.
Tracing
Tracing the evaluation of DSolve
as the following:
eq = D[y[x], x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0;
traceRes = Trace[DSolve[eq, y[x], x,
GeneratedParameters -> ThisIsForGeneralC],
{TraceInternal -> True,
TraceOff -> _Message}];
and formatting (using the levelIndentFunc
function I mentioned here) and exporting the result (it will be around 200 MByte):
Export["[Trace-result] DSolve.txt", levelIndentFunc @ traceRes, "String"]
Searching the "unique" footprint ThisIsForGeneralC
we made on purpose, it's not hard to find where the problem comes from.
Analysis
Here, from the trace result we can see, MMA eventually arrives a point like:
DSolve`DSolveFirstOrderODEDump`f = {{{y[x] -> E^Cos[x]*DSolve`DSolveFirstOrderODEDump`const[2] + E^Cos[x]*Integrate[DSolve`DSolveFirstOrderODEDump`const[1]/E^Cos[K[1]], {K[1], 1, x}]}}}
DSolve`DSolveFirstOrderODEDump`f = DSolve`DSolveFirstOrderODEDump`f[[1,1,1,2]]; {DSolve`DSolveFirstOrderODEDump`f, DSolve`DSolveFirstOrderODEDump`g} = {Coefficient[DSolve`DSolveFirstOrderODEDump`f, DSolve`DSolveFirstOrderODEDump`const[1]], Coefficient[DSolve`DSolveFirstOrderODEDump`f, DSolve`DSolveFirstOrderODEDump`const[2]]}; {{y[x] -> -((ThisIsForGeneralC[1]*D[DSolve`DSolveFirstOrderODEDump`f, x] + D[DSolve`DSolveFirstOrderODEDump`g, x])/(DSolve`DSolveFirstOrderODEDump`h*(ThisIsForGeneralC[1]*DSolve`DSolveFirstOrderODEDump`f + DSolve`DSolveFirstOrderODEDump`g)))}}
which is actually
f = {{{y[x] -> E^Cos[x]*const[2] + E^Cos[x]*Integrate[const[1]/E^Cos[K[1]], {K[1], 1, x}]}}};
f = f[[1, 1, 1, 2]]
{f, g} = {Coefficient[f, const[1]], Coefficient[f, const[2]]}
{{y[x] -> -((ThisIsForGeneralC[1]*D[f, x] + D[g, x])/(h*(ThisIsForGeneralC[1]*f + g)))}}
Note the f = Coefficient[f, const[1]]
part, which is incorrectly evaluated to 0
! That's the one to blame for our issue!
If we replace f
with the correct value:
f = E^Cos[x]*Integrate[E^(-Cos[K[1]]), {K[1], 1, x}];
We'll get effectively the same general solution as the one mentioned in OP:
{{y[x] -> -((ThisIsForGeneralC[1]*D[f, x] + D[g, x])/(h*(ThisIsForGeneralC[1]*f + g)))}}
Some perhaps fixes coming up to my mind include:
- Introducing new rule for
Integrate
(Please compareIntegrate[a b[x], {x, 0, 1}]
andIntegrate[a b[x], x]
); Or - Introducing new rule for
Coefficient
(Maybe not a good idea); Or - Using method other than
Coefficient
inDSolve
.
Comments
Post a Comment