MATLAB: Symbolic Integration Bug

bugMATLABsymbolic

Hi All,
Is this a bug of symbolic toolbox? It is kind of messing up when changing the signs.
clear all; clc;
syms x L1 L2;
L1val = 10;
L2val = 20;
Ma = -(x-L1)^2;
Mb = -(x^2+L1^2-2*x*L1);
Maint = int(Ma, x);
Mbint = int(Mb, x);
vpa(subs(subs(Maint, L1, L1val),x, 1))
vpa(subs(subs(Mbint, L1, L1val),x, 1))
ans =
243.0
ans =
-90.333333333333333333333333333333
Regards,
Baha

Best Answer

No bug. You are doing indefinite integration, which is permitted to have a constant of integration. You are evaluating at a single point rather than evaluating the difference between two locations, so the constant of integration is included in the value. It is permitted for the two forms to generate two different constants of integration.
If you were to
syms a
Maint = int(Ma, x, a, x);
Mbint = int(Mb, x, a, x);
then you would get the same result for the two.
Related Question