MATLAB: Indefinite integration returns different expression in R2015a and later releases

complexconstantexpressionindefiniteintegrationMATLABolddocssimplifywrong

Consider the following symbolic function:
>> f=@(x) sin(x)+2*cos(x)
Integrating the above function using "int" as follows,
>> syms x;
>> fInt=int(f(x),x)
we get the following expression in R2015a and later releases :
fInt = 
-2*cos(x/2)*(cos(x/2) - 2*sin(x/2))
Whereas, the desired expression is 2*sin(x)-cos(x).
Here the obtained result differs from the desired result only by a constant of integration, but we are able to obtain the desired simplified expression by executing the same code on older releases (R2014b and previous) .
Why do the newer releases give a more complicated answer while the older releases are able to give the simpler answer?

Best Answer

Integration results, like many results in MATLAB, can change as a result of enhancements to other functionality. For instance, changing the result of the "int" function on the expression "sin(x)+2*cos(x)" was not explicitly planned, however, this was the result of improving a different part of the functionality.
To obtain an expression closer to the desired expression, you can execute the following code:
>> simplify(fInt,'Steps',100)
Also, please note that in general, indefinite integration is a more complicated task than differentiation as stated in the documentation, and when using the "int" function, the obtained expression may differ from the desired expression by the constant of integration term.