I'm integrating the following expression:
sin(2*x)/4 - 8*sin(x)
In Matlab, I put in
syms x
int(sin(2*x)/4 - 8*sin(x))
and it returns
17*cos(x/2)^2 - cos(x/2)^4
In Wolfram, I input
int(sin(2*x)/4 - 8*sin(x))
and it returns
8 cos(x) - 1/8 cos(2 x) + constant
For the sake of comparing the two solutions, I put the following into Wolfram
int(sin(2*x)/4 - 8*sin(x)) == 17*cos(x/2)^2 - cos(x/2)^4
and it shows Matlab's solution gives a constant of integration 65/8
, whereas Wolfram leaves the constant of integration arbitrary. I'm glad I caught this because it makes a big difference in my final solution, albeit a constant. My question is, why does Matlab feel the need to provide a constant of integration, when in the end it's arbitrary? Seems kinda dangerous.
According to the int
documentation, "Results returned by int do not include integration constants". But clearly, some got introduced during the solution. So I guess a better statement would be: MATLAB doesn't introduce any new symbolic constants to the solution if one is found (unlike WolframAlpha implies but like Mathematica).
However, apparently, definite arbitrary constants introduced to, and possibly hidden in, the solution may be introduced by the solution algorithm. This is perfectly valid since an indefinite integral yields an infinite number of valid solutions sans initial or terminal data.
According to the MuPAD documentation of int
(MATLAB's symbolic engine), indefinite integrals are tackled via "table lookup or Risch integration", and I'm sure that's after some front-end parsing and simplification beforehand to boot. So whichever branch of the decision tree the symbolic engine went down ended up producing powers of trigonometric functions which indicate the introduction of constants upon their reduction. I don't know if this is standard practice. But I can see how giving the algorithm some leeway to introduce such constants may be beneficial for a robust solution method since symbolic indefinite integration is an extremely difficult task.
So to try and answer the question: "why does Matlab feel the need to provide a constant of integration, when in the end it's arbitrary?" It does it because it can, and the underlying algorithm determined it was the right course of action for some reason. Also, the solution is perfectly valid since it is arbitrary.
"Seems kinda dangerous." I would disagree. While not entirely ideal, the results of the integration will be correct once the appropriate data is introduced and used in tandem with the solution. If no such appropriate data exists, the problem is under-specified and any solution is valid to an arbitrary constant.