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 compare Integrate[a b[x], {x, 0, 1}]
and Integrate[a b[x], x]
); Or
- Introducing new rule for
Coefficient
(Maybe not a good idea); Or
- Using method other than
Coefficient
in DSolve
.