okay, I finally found a decent approach (in section 6.2 of https://numerical.recipes/book.html)