Incorrect indefinite integral on MATLAB? any ideas why matlab is giving me an incorrect answer here?
1 set of commands


syms x L N2
N2 = 6*x/L^2 - 2/L^2


N2 =
(6*x)/L^2 - 2/L^2


expand(int(N2*N2))


ans =
(4*x)/L^4 - 4/(9*L^4) - (12*x^2)/L^4 + (12*x^3)/L^4
The term 4/(9*L^4) should not be there, I have no idea where it is coming from...
If it is a constant, then why does the following integration yield no constant, since it is the same mathematical operation?:
2nd set of commands


expand(int(4/L^4 - (24*x)/L^4 + (36*x^2)/L^4))


ans =
(4*x)/L^4 - (12*x^2)/L^4 + (12*x^3)/L^4





 A: Indefinite integrals have an arbitrary constant term. This one is as good as any other real number.
Even if Matlab gives different answers when doing identical calls, it's not mathematically wrong.
On the other hand, Matlab manual states that Results returned by int do not include integration constants. (see More about $\to$ Tips) If this means the constant must always be $0$, it may be considered a bug, and you could ask directly to Mathworks. But this is a narrow interpretation of the statement, and it could as well mean that Matlab will not add a $+ C$ at the end on purpose.
However, bear in mind that even without an integration constant, the answer is ambiguous, when the primitive may be given in different but equivalent forms, like
$$\int \frac{\mathrm dx}{2\cosh x}=\arctan \left(\tanh \left(\frac{x}{2}\right)\right)+C=\arctan\left(e^x\right)+C'$$
Whereas $\arctan\left(e^x\right)\neq\arctan \left(\tanh \left(\frac{x}{2}\right)\right)$, and the difference is of course a constant, $\pi/4$. So, what does it mean here to not include integration constants?
