MATLAB: Vpaintegral() returns wrong answer for g(t) = (mod(t,5))^2

bugMATLABvpaintegralwrong answer

Hi,
I tried both vpaintegral() and integral() to integrate from 0 to 10.
integral() correctly returned 83.3333, but vpaintegral() strangely returned 333.333.
I don't know why this happened. Maybe there's a bug in vpaintegral()?
Any help is much appreciated.
Thank You in advance.
Code:
syms t real
g(t) = (mod(t,5))^2
fplot(g, [0 10])
vpaintegral(g, t, 0, 10)
g_mf = matlabFunction(g, 'vars', {t})
integral(g_mf, 0, 10)

Best Answer

Peculiar. If you look at g(t) you will see (well in my version of matlab):
g(t) = (mod(t,5))^2
g(t) =
t^2
Which shows that the mod is instantly evaluated. Further it didn't work to define five as a symbolic 5 either, the mod was determined. Peculiarly it did not work to include it explicitly in the vpaintegral either:
vpaintegral(mod(t,5)^2, t, 0, 10)
ans =
333.333
This was an interesting "feature".