I have a periodic function ff:
ff := Function[x, Piecewise[{{ff[x - 1], x >= 1}, {2 x, 0 <= x < 1}, {ff[x + 1], x < 0}}]]
Plotting it works fine:
Plot[ff[x], {x, -4, 4}, PlotRange -> {{-4, 4}, {-.5, 3}}]
But integrating it like this:
Integrate[ff[t], {t, 0, 5}]
What I get is a few of:
$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>
and a few of:
$IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
And it keeps running until I abort the evaluation. What's the problem? Thanks.
EDIT: Thanks for the answers. To avoid any more confusion, this is the signal I actually have to integrate. It's a bit more complex, and I wanted to know if that's the reason why it won't integrate, that's why I went for the sawtooth signal.
s := x \[Function] Piecewise[
{
{s[x + 2 Pi], x < -Pi},
{0, -Pi <= x < -Pi/2},
{Cos[x], -Pi/2 <= x <= Pi/2},
{0, Pi >= x > Pi/2},
{s[x - 2 Pi], x > Pi}
}
]
Plot command:
Plot[s[x], {x, -8, 6}, PlotRange -> {{-8, 6}, {-.5, 6}}]
EDIT 2:
Using this much simpler, "automatically" periodic definition for the signal, there seems to be no problem with integration:
s = Function[x, Piecewise[{{0, Cos[x] < 0}, {Cos[x], Cos[x] >= 0}}]]
Still doesn't answer the question why Mathematica isn't able to integrate the signal when it's defined like above.
(2/T)*Integrate[ff[t], {t, 0, T}]]
, where T is the period. $\endgroup$SawtoothWave
. See here. $\endgroup$s := x \[Function] Piecewise[{ {s[x + 2 Pi], x < -Pi}, {0, -Pi <= x < -Pi/2}, {Cos[x], -Pi/2 <= x <= Pi/2}, {0, Pi >= x > Pi/2}, {s[x - 2 Pi], x > Pi} }]
This the one I actually have to integrate. Again, plotting works, but integrating it doesn't work at all. $\endgroup$