Nearest overlapping time for periodic flashing light bulbs

122 Views Asked by At

Assume that we have two light bulbs in the room. Each bulb turns ON at fixed periodic intervals and stays ON for fix time period before turning OFF. The ON time is part of the periodic interval; ON time + OFF time = 1 cycle. Let's call them Bulb A and Bulb B with periodic times as 'Ca' and 'Cb'. The time the bulb stays ON is 'Ta' and 'Tb' respectively. Is there a mathematical expression to determine the next time instance when both the bulbs are in the "ON" state at the same time? Not necessarily turning on at the same time.

We can assume both periodic cycles start at the same time and the periodic times (Ca, Cb) are not multiples of each other.

To be more explanatory, I provided some numbers below

Bulb A peroidic time : Ca = 470ms.

Bulb B periodic time : Cb = 1280ms.

Bulb A stays on for Ta = 10ms.

Bulb B stays on for Tb = 20ms.

Assuming that both cycles start at exactly the same instance (time t = 0),

Bulb A ON time : (-5 to 5), (465 - 475), (935 - 945), ....

Bulb B ON time : (-10 to 10), (1270 - 1290), (2550 - 2570), ...

I am interested in knowing when will be the earliest time instance when both bulbs will be in "ON" state at the same time.

A simplified version of the problem is to assume Ta = Tb = impulse/Dirac delta function, meaning we treat it as overlap only at the exact instance. In that case, the solution is just the Least Common Multiplier of the cycle time of A and B (For numbers provided earlier solution is 60160ms ~ 60 secs)

I am interested in knowing if there is a mathematical way to solve if Ta and Tb are not zero and not equal.

1

There are 1 best solutions below

5
On

Defining variables:

Let the $2$ bulbs be $B_1$ and $B_2$.
Let the $1^{st}$ bulb be ON for $x$ units of time and OFF for $y$ units of time.
Let the $2^{nd}$ bulb be ON for $i$ units of time and OFF for $j$ units of time.
So, Periodic cycle for $B_1=x+y$ and that for $B_2=i+j$.

Let $a\in[0,x+y)$ and $b\in[0,i+j)$.
Here, $a$ and $b$ respectively are the times taken by $B_1$ and $B_2$ to complete the incomplete cycle. (Which would be $a=5+460=465$ and $b=10+1260=1270$ in your case).
Note: A cycle is completed after the bulb is OFF again (and completes the OFF period too which is $y$ and $j$ respectively). The next cycle starts the moment bulb switches ON again.

Finding the time, $T$:

Now we want to find the earliest time, $T$ when both bulbs will be ON at the same time. That is:
$T=a+(x+y)m=b+(i+j)n\qquad$ where $m,n\in\Bbb Z$
Note: Essentially $m$ and $n$ are $2$ instances (consider them $T_1 \ \& \ T_2$ respectively for your ease) after which both the bulbs will be ON again.

Let $(x+y)\leq(i+j)$, then,
$$m=\frac{b-a+(i+j)n}{x+y}$$ For the above expression we want integer solution(s) for $m,n$.

Your First Case:

In your case, putting in all the values, we have:
$$\begin{align} m &= \frac{1270-465+1280n}{470} \\ &= 1+2n+\frac{67+68n}{94}\end{align}$$ But for any $n\in\Bbb Z$ we don't have $(67+68n)\mod94 = 0$.
Thus, the $2$ won't ever be ON again at the same time.
Note: To clear any confusions, the above statement may be better put as: The $2$ bulbs will never Switch ON together at the same time.


Your Second Case:

In the case where $a=b=0$, we have: $$\begin{align} m &= \frac{0+1280n}{470} \\ &= 2n+\frac{34n}{47}\end{align}$$ For $n=0$ obviously we'll get $m\in\Bbb Z$, so $T=0+1280(0)=0$.
Note: In general, $n=47k$ and we want $n$ to be the smallest integer to get smallest $T$ so that'd be at $k=0$.
Surprised that why we didn't get $60160$? Follow up to know.

In the case where $a=470 \text{ and } b=1280$, we have: $$\begin{align} m &= \frac{1280-470+1280n}{470} \\ &= 1+2n+\frac{34(n+1)}{47}\end{align}$$ For $n=46$ obviously we'll get $m\in\Bbb Z$, so $T=1280+1280(46)=60160$.
Note: In general, $n=46+47k$ and for smallest $n$, $k=0$ (always $k$ need to be put $0$ since we are interested in smallest time).
Note 2: Kindly see why now we get $60160$ unlike in case $a=b=0$. So be careful while taking the values of $a$ and $b$.


Final note: I took different variables than what you suggested so as to arrive at a more general and "neat" answer/solution.

And also, it may not always be easy to find/check whether we'll get integer solution(s) for $(m,n)$ for which you may instead check here and that's how I confirmed my result too.