My question is basically the inverse of this question. That question asks how to get the volume of liquid in an inverted cylinder given the height. In my case I know the volume of liquid and the dimensions of the container, but I need to calculate the height of liquid.

This equation $V = L (R^2 \cos^{-1} (\frac{R-h}{R}) - (R - h)\sqrt{2Rh - h^2})$ gives the volume from a radius R, a height h and a length L. I tried to solve it for h but I could not do it on my own or via Wolfram Alpha.

Currently I am calculating the height from the volume in a computer program using the above equation and binary search. Is there a better way?


1 Answer 1


Equations which contain trigonometric and algebraic terms do not show analytical solutions and then only numerical methods can be used.

You can reduce the problem to an equation with no dimension defining $x=\frac h R$ which gives $$a=\frac V {L R^2}=\cos ^{-1}(1-x)+\sqrt{x(2-x)} (x-1)$$ and solve for $x$. Since the equation is not linear, the method will be iterative and a starting guess is required.

The function given in the rhs can be approximated by $\frac \pi 2 x$ and knowing $a$, this gives a rough estimate $x_0=\frac {2a} \pi$.

Now, the simplest will be Newton method which, starting from $x_0$, will update the guess according to $$x_{n+1}=x_n-\frac{f(x_n)}{f'(x_n)}$$ Using $$f(x)=\cos ^{-1}(1-x)+\sqrt{x(2-x)} (x-1)-a$$ $$f'(x)=2 \sqrt{(2-x) x}$$

For illustration purposes, let us use $a=\frac 3 4$; so, the method will generate the following iterates $$\left( \begin{array}{cc} n & x_n \\ 0 & 0.4774648293 \\ 1 & 0.5798249292 \\ 2 & 0.5765888390 \\ 3 & 0.5765861544 \end{array} \right)$$

which is quite fast.

You can improve that starting guess when the tank is not almost not totally emptu or full, approximating the rhs using a Pade approximant built around $x=1$. This gives $$\cos ^{-1}(1-x)+\sqrt{x(2-x)} (x-1)\approx \frac{\frac{1}{12} \pi (x-1)^2+2 (x-1)+\frac{\pi }{2}}{\frac{1}{6} (x-1)^2+1}$$ which reduces to the problem of a quadratic equation in $(x-1)$ the solution of which being $$x_0=\frac{-2 (a+6)+\sqrt{6} \sqrt{24-(\pi -2 a)^2}+\pi }{\pi -2 a}$$ For the above case, this would give $x_0 =0.577385$ and Newton method should converge in one iteration.

For the case where the tank would be "almost" empty, using Taylor expansion around $x=0$, you have $$f(x)=\frac{4}{3} \sqrt{2} x^{3/2}+O\left(x^{5/2}\right)-a$$ and ignoring higher order terms, an estimate could be $$x_0=\frac{1}{2} \left(\frac{3a}{2}\right)^{2/3} $$ For the considered case, this will be $x_0\approx 0.540844$.


We can improve all of the above using as an approximation $$\cos ^{-1}(1-x)+\sqrt{x(2-x)} (x-1)\approx \frac{a+bx+c x^2}{1+dx+e x^2}$$ Imposing that the function values be the same for $x=0$, $x=1$, $x=2$ and that the first and second derivatives be the same for $x=1$, we get $$a=0\qquad b=\frac{\pi ^2}{4}-\frac{\pi }{2}\qquad c=\frac{\pi }{2}-\frac{\pi ^2}{8}\qquad d=\frac{\pi }{2}-2\qquad e=1-\frac{\pi }{4}$$ This gives, as an approximation valid for any value of $a$ $$x\approx \frac{8 a-\sqrt{\pi } \sqrt{(\pi -4) (\pi -2 a)^2+4 \pi }-2 \pi (a+1)+\pi ^2}{(\pi -4) (\pi -2 a)}$$ For the test value $a=\frac 34$, this gives $x=0.568747$. Using the above formula for $x_0$, Newton method should converge in one or two iterations.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .