Have a look at the Apache commons math library. I haven't used it for this in particular, but probably has something in there worth trying.
Commons Math: The Apache Commons Mathematics Library