Using Decimal object when finding roots of an equation numerically (fsolve)

27 Views Asked by At

I have an equation that I'd like to solve numerically. However, the constant in the equation can have extreme values (think 10^31) and thus require higher decimal precision than Python's standard 15 places.

For context, the equation I am trying to solve is x^2/(1-x) - v = 0 where v ranges from 5609860.543899053 to 3.446100182453627e+31. The answer should be some number extremely close to 1, such as 0.9999999999999998 or something like that. Definitely needs more decimal places than 15.

I've been using Decimal for this, setting

getcontext().prec = 50

But I've found that I cannot use Decimal objects in scipy.optimize's fsolve. Is there any way around this?

0

There are 0 best solutions below