This integral has the same issue as one in Slow plot for integral involving FractionalPart and sine,
but there seems to be a bug or limitation to DSolve
that prevents using it straight out of the box to perform the integration.
The main problem is that until somewhat recently, Mathematica could not handle most discontinuous integrands at all. With improvements to WhenEvent
, these can be handled by DSolve
over a definite and finite interval. So even though it is possible (and not very difficult) to write a program in this special case to calculat the OP's indefinite integral in terms of an indefinite Sum
, I don't believe there is a way to get Integrate
or DSolve
to do that for you.
However, we can get it to solve the integral for all x
in a (reasonably sized) finite interval.
To get around the bug/restriction, we have to tweak the settings for PiecewiseExpand
to get an expansion of Sign[Cos[q]]
that DSolve
can deal with.
With[{q1 = 0, q2 = 20},
Assuming[q1 <= q <= q2,
With[{opts = Options@PiecewiseExpand},
Internal`WithLocalSettings[
SetOptions[PiecewiseExpand,
Method -> {"ConditionSimplifier" -> (Reduce[# && $Assumptions] &)}],
ii = DSolveValue[
{y'[q] == PiecewiseExpand@Sign[Cos[q]]/(q + 1), y[0] == 0},
y[q], {q, q1, q2}],
SetOptions[PiecewiseExpand, opts]
]]]];
Compare with numerical integration:
ff = NDSolveValue[{y'[q] == Sign[Cos[q]]/(q + 1), y[0] == 0}, y[q], {q, 0, 20}];
Plot[{ii, ff}, {q, 0, 20}, PlotStyle -> {Thickness[0.015], Thickness[0.006]}]
