After some simple algebra, this is equivalent to the calculation of "internal rate of return" in finance, on which there is a large literature and many implementations (e.g. in Microsoft Excel).
In general, this can only be solved numerically, by a nonlinear root-finding algorithm. The function you're searching for the root of is monotonicbounded and smooth, so there's no problem of convergence. I recently implemented this using Brent's method, but bisection or the secant method work almost as well and are easier to implement.