# [SciPy-user] Solving an equation using scipy.optimize.newton

fdu.xiaojf@gmai... fdu.xiaojf@gmai...
Wed Sep 5 20:57:41 CDT 2007

```Thanks Dominique and dmitrey,

Dominique Orban wrote:
>
>
> On 9/5/07, *fdu.xiaojf@gmail.com <mailto:fdu.xiaojf@gmail.com>*
> <fdu.xiaojf@gmail.com <mailto:fdu.xiaojf@gmail.com>> wrote:
>
>     Hi all,
>
>     I'm trying to solve an equation f(x) = 0 with scipy.optimize.newton .
>
>     However the problem isn't so simple. There are bound constraints for my
>     equation: the equation cannot be evaluated when x is out of [Min,
>     Max], but
>     the root is always in the interval of [Min, Max]
>
>     When newton() iterates to find a root, it sometimes try to evaluate the
>     equation with a x out of [Min, Max], and then error occurs.
>
>     How to solve this problem ?
>
>     I couldn't easily find two points with different signs every time,
>     so methods
>     like brentq don't work here.
>
>
> There are variants of Newton's method that can handle bound constraints.
> However, another way to treat your problem would be to solve the
> optimization problem:

Are there any trust region optimization method with python interface ?

>
> minimize   0
> subject to   f(x) = 0, and Min <= x <= Max.
>
> The objective function of this problem is constant, so any x satisfying
> the constraints is optimal, and is what you are looking for. Note
> however that you now have an optimization problem with nonlinear
> equality constraints.
>
> If a solver isn't able to identify a point satisfying the constraints,
> it will usually guarantee some sort of 'proximity property', i.e., the
> final iterate will minimize the residual of constraints in some sense.
>
> Dominique
>

I can transform my problem to a bound constrained optimization problem,
but I still have to find an optimization solver who only evaluate my
equation in trust region([Min, Max]). Will lbfgsb or tnc meet the
requirement ?

Regards,

```