MATLAB: Symbolic ODE solver Error

errorodesymbolic

Wrong answer!
>> simplify( dsolve('Dy + y * cos(x) = sin(x) * cos(x)', 'y(0) = 0') )
ans =
sin(2 x) (-1 + exp(-cos(x) t))
- 1/2 ------------------------------
cos(x)
>>
The argument of the exponential should be sin; also, where's the t coming from?

Best Answer

Try
syms y(x)
eqn(x) = diff(y(x), x)+y(x)*cos(x) == sin(x)*cos(x);
dsolve(eqn,y(0)==0)
Note: the above includes a work-around for a bug in current versions of the symbolic toolbox. If you were to assign to eqn instead of to eqn(x) then the dsolve() would fail.
I am not sure why it produces the result it does for the literal case; it is probably a bug.