Solvers Python or Apache

I wrote this before we access to Apache math. May be useful for you. The polyfit() function is what I think you're looking for.