# "Mixed rate" problems

I don’t know if there’s a better term for this, since I made the term and the type of problem up on the spot, but I find myself struggling with what appears to be third grade math and it’s rather vexing.

It’s hard to explain, so I made up a word problem to illustrate it better:

A pool filled with g[sub]0[/sub] gallons of water naturally loses water due to evaporation at a rate of 1 gallon/week. To offset this, every other saturday the groundskeeper fills the pool with two gallons of water. If today the pool has been filled, what is the amount of water in the pool w weeks from now?

The obvious solution to this is that you have an “empty rate” of 1 gal/wk and a “fill rate” of 2 gal/2 wk, so

g(w) = g[sub]0[/sub] - 1 gal/wk * w + 2 gal/2 wk * w = g[sub]0[/sub] - 1 gal/wk * w + 1 gal/wk * w = g[sub]0[/sub]

So what’s the amount of water after 1 week? g(1wk)= g[sub]0[/sub]. Which is… clearly wrong, it’s g(1wk) = g[sub]0[/sub]-1gal (since it’s only filled fortnightly).

For this specific case you can actually find a nice-ish solution:

g(w) = g[sub]0[/sub] - 1 gal/wk * w + 2gal/wk * ( (w+1) mod 2) * w // Note, depending on how units work with modular arithmetic, coefficient is gal/wk[sup]2[/sup] – I still don’t think the units make much sense in that case

Unfortunately, it seems… hacky. I really don’t like the fact that the units of the of the last term is in gallons per a week, 2 gal/wk really makes no intuitive sense. It’s also incredibly specific to a problem of precisely this form, anything that’s not on a precise interval (i.e. “once every n weeks the pool is filled n gallons”) doesn’t work. It also, to my knowledge, doesn’t really take into account “half-steps”, such as how many gallons would be in the pool after a week and a half – though I’ll admit I’m not clear on the particulars of continuous modular arithmetic.

Is there an more elegant way to state a solution to a problem of this type? The only other method I can think of (for the general case) just involves a piecewise function, but I don’t like piecewise functions unless they’re absolutely necessary – they’re kind of messy. But I can’t deny that the graph looks a LOT like a piecewise function, so maybe that’s where this type of problem is doomed to go.

Note that the word problem is a really simple case. A more complex case might be that for three days every week, the pool has a pump on that fills the pool at a rate of x gallons per day, or in the extreme case that it’s filled by one gallon two random days (with 100% certainty) in a recurring n-day period. It also need not be periodic like this one, maybe you have a net loss or gain of whatever you’re measuring. So don’t get too myopic on the really simple problem I presented, I’m talking about strategies for solving such a problem generally.

I don’t need this for school, research, work, or anything. The idea just came to my head and now it’s bugging me.

You could also use the unit step u(t), for t >= 0 u(t) = 1; for t<0 u(t) = 0

g(w) = g_0 -1w + 2wu(cos(2pi*w/2) - 1)

Wait, that only adds water when w is exactly even…still, maybe there is something there that is usable

I don’t see a way to avoid a piecewise function for any of the cases you’re talking about. Even the modulo function that you used in your “nice-ish” solution is really a piecewise function, since it’s not continuous. Basically, you have a certain cycle that repeats every N days, which results in an average net gain or loss of M gallons over the course of one cycle. The solution can then be written as

g(t) = g[sub]0[/sub] + M*t/N + g[sub]per/sub

where g[sub]per/sub is a periodic cycle of period N, i.e., g[sub]per/sub = g[sub]per[/sub](t + N) for all t. Defining this periodic function for the time interval from 0 to N then defines it for all t. In all of the cases you’re talking about, though, the single-cycle definition is only defined piecewise.

Really what you’re doing is trying to solve the differential equation

dg/dt = r(t)

where r(t) (the rate at which the pool is being filled as a function of time) is a periodic and discontinuous function. This means that g(t) is the integral of r(t). If the function r(t) is discontinuous, its integral g(t) will not be “smooth” (after all, its derivative is discontinuous.) And you’re going to have a lot of trouble writing out function with discontinous derivative without using a piecewise definition.

I think youse guys are trying to make this waaaaaaaaay too complicated. Try this:

The function for the amount of water (in gallons or any other unit) in the pool at any time is a sawtooth function – See the top half of the top-most illustration at the Sawtooth Wiki. But for your function, the sloped lines would be sloping down to the right instead of up to the left, since the water level is decreasing.

You need some variation on the mod function to deal with this.

Off the top of my noggin, I’m going to suggest:

g[sub]w[/sub] = g[sub]0[/sub] - ( w mod 2 )

This should just work just fine for fractional w – For example, ( 6.5 mod 2 ) is 0.5, and ( 7.5 mod 2 ) is 1.5

Just before the pool is refilled, say at week w = 7.9, the pool will have:
g[sub]7.9[/sub] = g[sub]0[/sub] - ( 7.9 mod 2 ) = g[sub]0[/sub] - 1.9 gallons. (Just approaching 2 gallons down.)

As soon as the pool is refilled, at week w = 8, then the pool again has:
g[sub]8[/sub] = g[sub]0[/sub] - ( 8 mod 2 ) = g[sub]0[/sub] - 0 = g[sub]0[/sub] gallons.

(Note that when w is an even integer, that is, just at pool-refilling-time, this gives the volume of water just after refilling, rather than just before.)

Minor oops – missed edit window – This is supposed to say:
sloping down to the right instead of up to the right.

Can’t you just look in the pool. If it’s full don’t add any. If not it’s short a gallon.

Senegoid’s comment about it being a sawtooth function gave me an idea…you should be able to use a fourier series to represent the pool volume.

Nowhere as neat as Sengoids solution, but it is another way to solve it.