As far as I know, if a set of functions f,g,h,...
are all Riemann integrable then the definite integral of the sum f+g+h
over the interval [1,x]
should be equal to the sum of the separate integrals over [1,x]
of f
and g
and h
.
In my case, the integrals must be calculated using NIntegrate
because Mathematica won't play nicely with the Floor
function element in the functions.
But for whatever reason, the integral of the sum does not match the sum of the integrals:
f[x_] := Sum[Floor[u]*((k*u*Cos[Pi*(u + k*u - x)])/(u + k*u - x)),
{k, 1, Floor[x] - 1}];
g[x_] := Sum[Floor[u]*((k^2*u*Cos[Pi*(u + k*u - x)])/(u + k*u - x)),
{k, 1, Floor[x] - 1}];
h[x_] := Sum[Floor[u]*((k^2*u*Cos[k*Pi*u - Pi*x])/(k*u - x)),
{k, 1, Floor[x] - 1}];
Table[{x, NIntegrate[f[x] + g[x] - h[x], {u, 1, x}],
NIntegrate[f[x], {u, 1, x}] + NIntegrate[g[x], {u, 1, x}] -
NIntegrate[h[x], {u, 1, x}]}, {x, 2, 5, 1/2}]
{{2, 300.5118851, 442.9860989}, {5/2, 736.7297006, 743.1447953}, {3, 894.7316167, 904.577171}, {7/2, 1550.215739, 1571.798798}, {4, 1770.592955, 2035.875269}, {9/2, 2678.596999, 2687.159346}, {5, 2984.444006, 3038.680717}}
Is this just a result of using NIntegrate
? If It's numerical error, is there a work-around to obtain more accurate results?
Or am I doing something completely wrong, either in my coding or in my maths?
NIntegrate
gives me a bunch of "failed to converge" errors. It makes me think that is where to look for the problem. $\endgroup$x
vsu
thing is deliberate; this is part of a bigger function with many variables, and the required result is its value for a givenx
. $\endgroup$