Differential Equations in Dilution Problems

With evening tranquility with my wife

Suraj Regmi
8 min readDec 6, 2023

Swimming pool

It was just the starting of the month of December. Just when winter was revealing itself, the lights in the swimming pool of our apartment were refracting through the swimming pool’s water. We love to sit by the swimming pool no matter what the season is. Anyway, winters are not that bad in Huntsville.

Photo by Fernando Álvarez Rodríguez on Unsplash

Chlorine is put in the swimming pool to kill germs. It kills germs such as E. Coli and Salmonella [1]. It also kills germs which cause diseases such as diarrhea [1]. However, putting too much chlorine can be harmful. There have been incidents of minors being taken to hospital because of too much chlorine in the swimming pool [3]. CDC recommends at least 1 ppm in swimming pools [1] and the water and health council recommends the range of acceptable chlorine levels as 1 to 5 ppm [3]. Our apartment considers 1.5 ppm as the best concentration of chlorine and maintains that regularly.

The average pool needs about 18000 gallons of water to fill [5]. The swimming pool of my apartment has 15000 gallons of water. So, it is of an average size. To maintain ppm levels at 1.5 ppm, let’s calculate how much pounds of calcium hypochlorite the apartment needs.

Calcium hypochlorite, a source of chlorine

PPM stands for parts per million. It is calculated by weight. 1 and a half ppm means 1.5 pound chlorine in one million pounds of water (120,000 gallons of water). 1 and a half pound is 90 ounces.

So, for our swimming pool (15000 gallons of water), we need 90 / 120000 * 15000 ounces.
= 11.25 ounces of chlorine
= 17.3 ounces of calcium hypochlorite (65% available chlorine)

So, we had to put 17.3 ounces of hypochlorite in the 15000 gallons of water but the operator mistakenly put 20 ounces of hypochlorite. Now, how can the operator rectify such that the concentration is kept at 1.5 ppm?

Solutions from my wife

My wife has her peculiar characteristics of giving me solutions as soon as I pose her a problem. While I was still thinking about the problem itself, she had already given me two solutions and started to spell out the third one. I paused her, took our my diary, and noted her solutions one by one. She came up with four solutions in no time, each one optimal than the previous ones. While she was doing that, I remembered a time when I was preparing for FAANG leetcode interviews. The approach was to keep optimizing the solutions. Normally, I would start with the brute-force solution and keep optimizing.

I know you are curious to hear her solution, perhaps, much more looking forward to her solutions than mine. You also probably have already guessed that my solution involves differential equations.

Costs

The Huntsville Utilities has tiered rate for water usage [6]. I am taking the highest rate and rounding it up to $5 per 1000 galloons. Calcium hypochlorite costs 34 cents per ounce on Amazon [7].

Solution 1

She said she would first drain out all the chlorinated water and then pump in the fresh water with appropriate amount of chlorine. This is the most straightforward solution anyone can think of. I calculated the cost it would take. It would take total of 80.9 (5 * 15 + 17.3 * 0.34) dollars.

Solution 2

Right after she gave the first solution, she came up with another solution. She said we can extract out excess 2.7 ounces of chlorine using some chemical techniques. While this might be a cool approach in the eye of a chemist, it might be a costlier approach than the most straightforward solution because it might require advanced methods.

Solution 3

Her enthusiasm fueled a continuous stream of solutions. At some time, I thought I should have just enjoyed the swimming pool lights. :D

She said we could just keep adding more water until we reach the concentration we needed. She continued, “Originally, we had to put 17.3 ounces in 15000 gallons of water i.e., 867 gallons per ounce. Right now, we have 20 ounces. So, at the rate of 867 gallons per ounce, we need water of 17341 (867 * 20) gallons. So, why not add 2341 more gallons of water?” It is not complex like the second solution. But we do not have space to add more than two thousands of gallons of water in the swimming pool. The swimming pool barely has a free space. Nevertheless, I was loving her thought process.

Solution 4

Here, she said that we could get rid of one-third chlorinated water (i.e., 5000 gallons). That got rid of one-third hypochlorite (i.e., 20 / 3 = 6.67 ounces). “Now, we have 13.34 ounces in the pool. Let’s add more 17.3–13.34 = 3.96 ounces of hypochlorite and 5000 gallons of water. Then, tada! We have right concentration!”, she exclaimed. I calculated the cost to implement this solution. It takes 26.35 (5 * 5 + 0.34 * 3.96) dollars. This is really good optimization, I replied.

These four solutions are technically correct but different in a lot of respects. The first was straightforward but costly. The second is cool but impossible without advanced chemistry techniques (I don’t even know if it is possible). The third solution is limited by our free space constraint. The fourth one is relatively more complex and arbitrary in the amount of discarded chlorinated water but costs just one-third of the cost of the first method. Most of the problems in the real world are also like this. There are multiple technically-correct solutions to a problem but we need simple-enough affordable and practical solution.

Let’s indulge in mathematics

Now, let’s indulge in mathematics of this problem using differential equations.

At first, let’s define this problem mathematically.

Let x be the ounces of calcium hypochlorite in the swimming pool.
Initially, we have 20 ounces of calcium hypochlorite in our pool, i.e., x_initial = 20.
Our target is to have 17.3 ounces of calcium hypochlorite in our pool, i.e., x_target = 17.3.

I am making here a setup to solve this problem. I am pumping in fresh water at the rate of 100 gallons per minute and draining out chlorinated water at the same rate (100 gallons per minute). This helps maintain constant volume of water in the swimming pool i.e., 15000 gallons. I am also stirring the pool along the way to keep constant spatial chlorine concentration.

Though the volume of water is constant, I am continuously loosing the chlorine through the outflow of chlorinated water. At t = 0, the amount of calcium hypochlorite I have is 20 ounces.

So, x(t = 0) = x_initial = 20.

If I keep doing this indefinitely, the chlorine concentration will keep on diminishing more and more.

My goal here is to find out the time “t” when the amount of calcium hypochlorite is 17.3 ounces.

Suppose we have started the process and we are at a time instant “t” when the amount of calcium hypochlorite is “x”. Let’s take a tiny time interval, Δt at that time. At Δt time, 100 * Δt gallons of chlorinated water has been drained out. The amount of hypochlorite Δx lost at time Δt can be found by the following reasoning:

At an instant of time “t”, 15000 gallons of chlorinated water has “x” amount of calcium hypochlorite.

The approximation for the change in amount of hypochlorite weight i.e., Δx during the tiny time interval Δt can be calculated by assuming that the chlorine concentration remains constant throughout the tiny time period, Δt. This is a reasonable approximation for a very small time period, Δt.

15000 gallons of chlorinated water has approximately x ounces of hypochlorite at the time “t”.
So, 100 * Δt gallons of chlorinated water has approximately 100 * Δt * x / 15000 ounces of hypochlorite.

Therefore, Δx ≈ - 100 * Δt * x / 15000
Δx / Δt ≈ - x / 150

As Δt → 0,
dx / dt = - x / 150
⇒ dx / x = - dt / 150
⇒ lnx = -t / 150
⇒ x = ce^(-t / 150) — — — (I)

Equation (I) gives a family of solutions. To find the particular solution, we put the initial condition, i.e., at t = 0, x = 20.

20 = c * e⁰
So, c = 20

Therefore, equation (I) becomes:
x = 20 * e^(-t / 150) — — — (II)

Equation (II) gives us the equation for the amount of calcium hypochlorite in terms of time, t. It is interesting to see that the amount never goes to absolute zero. It just approaches zero as the time “t” approaches infinity.

When should we stop?

Now, let’s find out when we should stop the pumping and draining process. We need to find out the time “t” when x = 17.3.

17.3 = 20 * e^(-t / 150)
⇒ t = -150 * ln(17.3/20) = 20.75 minutes

So, we need to stop the process at 20.75 minutes.

What is the cost?

I believe you are curious to see the cost of this process too and compare with others. The water is being pumped at the rate of 100 gallons per minute. So, it pumps 2075 gallons in 20.75 minutes. We need not add any calcium hypochlorite. So, the cost is just the cost of water (we are not counting pumping/draining cost in any of the solutions). Therefore, the cost turns out to be 10.38 (2.075 * 5) dollars. This is just 40% of the cost of the fourth solution and slightly more than one-tenth of the first solution. Amazing, isn’t it?

My wife’s thoughts

This was the solution I presented to my wife. She gave her four solutions in less than four minutes whereas it took me like 10 minutes to show and explain my “differential-equations” solution to her. However, she was impressed with my solution. She remarked the solution as more general and versatile. She said she did not think in terms of “time” dimension. She was also awe-inspired by the use of differential equations and integrations. It was cool for her to see the use of mathematical concepts such as logarithms and exponentials. I served my purpose of helping her see mathematics in a fun and useful way. I was smiling when she was finishing her thoughts and we were returning to our apartment from the pool.

Readers,

We use mathematics and numbers in our daily life in different forms. I believe mathematics can be intuitive to anyone and should be accessible to anyone living in any part of the world. As most of the disciplines are either built on top of mathematics or incorporate some aspect of mathematics to quantify something, it helps to have a good foundation of mathematics. The mathematical articles I write are my attempts to relate the abstract concepts of mathematics to the real world. By showing usefulness of mathematics in the real world, I want to help readers develop an interest in mathematics. Sometimes, showing beauty of mathematics can also provide motivation. If you have any suggestions on the topics you love to read an article or any other general suggestions, feel free to give a comment here or contact me in LinkedIn or email me at regmi125@gmail.com.

References

  1. https://www.cdc.gov/healthywater/swimming/residential/disinfection-testing.html
  2. https://www.vcstar.com/story/news/local/communities/conejo-valley/2018/10/03/authorities-respond-20-people-exposed-pool-chemicals-t-o/1517291002/
  3. https://www.livestrong.com/article/254114-health-effects-of-high-chlorine-in-swimming-pools/
  4. http://www.idph.state.il.us/envhealth/factsheets/Hyperchlorination.htm
  5. https://www.watercalculator.org/footprint/outdoor-water-use-at-home/
  6. https://www.hsvutil.org/residential_services/residential_rates.php
  7. https://www.amazon.com/Swim-Cal-Chlor-Pool-Chlorine-Granules/dp/B002WKS6D4?th=1

--

--

Suraj Regmi

Data Scientist at Blue Cross and Blue Shield, MS CS from UAH — the views and the content here represent my own and not of my employers.