# Write code that finds the ripple of a function (existing code finds the wrong answer)

I have the following code:

Clear["Global*"];
u = 5;
\[Tau] = (1/2)*10^(-3);
c = 10^(-6);
r = 1000;
y = u*Sum[((1 - E^((-t + \[Tau] + 4 n \[Tau])/(c*r)))  HeavisideTheta[
t - 4 n \[Tau]] HeavisideTheta[
t - \[Tau] - 4 n \[Tau]]) - ((1 - E^((-t + (3 + 4 n) \[Tau])/(
c*r))) HeavisideTheta[t - 4 n \[Tau]] HeavisideTheta[
t - (3 + 4 n) \[Tau]]), {n, 0, Infinity}];


If I plot (Plot[y,{t,0,15*10^(-3)},GridLines->{{(2*6+3)*\[Tau],(2*6+1)*\[Tau]},{y/.t->(2*6+3)*\[Tau],y/.t->(2*6+1)*\[Tau]}}]) the solution y, I get the following picture:

Now, we can see that the maximum and the minimum of the function $$y(t)$$ is found at the following times: $$t=(2\text{k}+3)\tau$$ and $$t=(2\text{k}+1)\tau$$ where $$k\in\mathbb{N}$$.

Question: I want to find the absolute difference between the maximum and minimum when $$t\to\infty$$.

My work:

Mathematically speaking, I want to find:

$$\lim_{\text{k}\to\infty}\left|\text{y}\left(\left(2\text{k}+3\right)\tau\right)-\text{y}\left(\left(2\text{k}+1\right)\tau\right)\right|\tag1$$

I know that the answer to the question must be:

$$\frac{5 (e-1)}{1+e}\approx2.31059\tag2$$

Coding this in Mathematica gave me:

In[1]:=FullSimplify[
Limit[Abs[(y /. t -> (2*k + 3)*\[Tau]) - (y /.
t -> (2*k + 1)*\[Tau])], k -> Infinity]]

Out[1]=Interval[{0, 20}]


Which is wrong. What is my mistake?

There 2 typo in My work. First, let plot function y, local minimum and maximum in one plot as follows

Clear["Global*"];
u = 5;
\[Tau] = (1/2)*10^(-3);
c = 10^(-6);
r = 1000;
y = u*Sum[((1 - E^((-t + \[Tau] + 4 n \[Tau])/(c*r))) HeavisideTheta[
t - 4 n \[Tau]] HeavisideTheta[
t - \[Tau] - 4 n \[Tau]]) - ((1 -
E^((-t + (3 + 4 n) \[Tau])/(c*r))) HeavisideTheta[
t - 4 n \[Tau]] HeavisideTheta[t - (3 + 4 n) \[Tau]]), {n, 0,
Infinity}];
Show[Plot[y, {t, 0, .01}],
ListPlot[{Table[({t, y} /. t -> (2*k + 1)*\[Tau]), {k, {1, 3, 5, 7,
9}}], Table[({t, y} /. t -> (2*k + 1)*\[Tau]), {k, {2, 4, 6,
8}}]} // N, PlotStyle -> {Blue, Red}]]


Therefore, we have minimum for even k , and maximum for odd k (Note, that it is not $$2k+3$$ and $$2k +1$$ like in the code In[1]:). Let define local extremum as follows

dy = (y /. t -> (2*k + 1)*\[Tau]);


Minimal and maximal values at k=100, 101 are (Note, that there is no limit for dy at k -> Infinity it is why there is Out[1]=Interval[{0, 20}]!),

minmaxy = {Limit[dy, k -> 100], Limit[dy, k -> 101]}

Out[]= {(5 (-1 + 1/E^100 - 1/E^99 + E))/(-1 + E^2), (
5 (-1 + E + E^102 - E^103))/(E^101 (1 - E^2))}


We can simplifier last expression by hand neglected by 1/E^100, 1/E^99 and so on, finally we have

 miny = (5 (-1 + E))/(-1 + E^2); maxy = (
5 (E^1 - E^2))/ (1 - E^2);

maxy - miny // Simplify

Out[]= (5 (-1 + E))/(1 + E)