0

A coworker gave me a puzzle, and I think I'm really close to a solution, I'm just missing a bit of math knowledge, and yes I'll be giving Math SE credit for getting this solution over the finish line :)

Let's say I've got a tank of known volume, and a set of cups for which I'm trying to deduce the volume. While I'm not allowed to touch the cups or the tank, my friends do know the volume of the cups, and have given me a long list of all the times they filled the tank using the cups, showing how many times each cup had to be used to fill the tank, like the following:

  • 1 Cup C, 2 Cup D
  • 3 Cup A
  • 3 Cup B, 2 Cup C
  • 1 Cup A, 1 Cup B, 2 Cup C
  • ...

My solution so far is that I populate a matrix with the above, and then right multiply it by a vector of the unknown cup volumes to get a "fill" vector, in which each row is the volume of the tank. If we let the volume of the tank be $1$, a vector of all $1$'s be $\vec{1}$ (more on this notation), a matrix containing all the weights of the fills shown above be $A$, and a vector containing the true volumes of the cups be $\mathbf x$ then:

$$\begin{align} \vec{t} & = A\mathbf x \\ & =\begin{pmatrix} 0 & 0 & 1 & 2\\ 3 & 0 & 0 & 0\\ 0 & 3 & 2 & 0\\ 1 & 1 & 2 & 0\\ 1 & 0 & 7 & 0\\ \end{pmatrix}\begin{pmatrix} x_1\\ x_2\\ x_3\\ x_4\\ \end{pmatrix}\\ A^{-1} \ \vec{t} & = \mathbf x \\ \end{align}$$

Problem solved! Except for two things:

First, the fills are approximate. The tank can be a bit overfilled and a bit underfilled and it's still considered full, and I can't update the $\vec{t}$ on the left side because I don't know the error, only how many of each cup it took to approximately "fill" the tank in previous fills. How do I account for error?

Second, I have a lot more rows than I need, which I can use to account for the approximate nature somewhat, but I'm not sure how. In the puzzle, I've got 10 cups and 100 previous fills, so I have a lot more data than necessary, and hopefully after adding in all those extra rows I'd still have something left-invertible. If I knew how this could be used to get more precise values for the volume of the cups, but I'm not sure how to mix statistics and linear algebra like this.

If you could provide some insight into how I account for the approximate nature of the tank volume and how I use the extra rows to improve the accuracy of the cup volume estimates, I'd really appreciate it. Thanks so much!

Edit

I've been looking into random matrices, and I think I can take what I had above and deconstruct the $A$ matrix into the "true" number of times each cup would have to be used in each fill of the tank $M$, and an error matrix $E$.

$$\begin{align} \vec{t} & = A\mathbf x \\ \vec{t} & = (M+E)\mathbf x \\ \left(M+E\right)^{-1} \ \vec{t} & = \mathbf x \end{align}$$

Now how do I account for the randomness of $E$ in the inversion? I also found this answer providing a formula for the inverse of the sum of two matrices, but I don't think I can use that either, given I don't know $M$ from $E$.

1 Answers1

1

So the matrix $A$ is presumably exact: you exactly fill the four cups some number of times and then use the tank to fill them to an amount close to 100%, but possibly deviating a little bit to either side. At the same time the system is overdetermined because you have five observations for four variables, which are not all exact because of overfilling/underfilling.

Unless the accuracy of a particular equation is considered to be much worse than the rest, this is a perfect recipe for ordinary least squares, which essentially picks $\mathbf{x}$ so that $A\mathbf{x}$ is as close to $\mathbf{t}$ as possible but generally none of the equations actually hold exactly.

Mathematically this amounts to $\mathbf{x}=(A^T A)^{-1} A^T \mathbf{t}$, and in this small case that implementation will work fine. There are better (i.e. performing better in approximate arithmetic) implementations out there; one of them is built into the backslash operator in Matlab and Octave.

Ian
  • 101,645