Search code examples
pythonnumpyscipyequation-solvingnonlinear-functions

Scipy - Non-linear Equations System with linear constraints (beginner)


I have seen this amazing example. But I need to solve system with boundaries on X and F, for example:

    f1 = x+y^2 = 0
    f2 = e^x+ xy = 0
-5.5< x <0.18
2.1< y < 10.6
   # 0.15< f1 <20.5 - not useful for this example
   # -10.5< f2 < -0.16 - not useful for this example

How could I set this boundary constrains to fsolve() of scipy? Or may be there is some other method? Would You give me a Simple code example?


Solution

  • It depends on the system, but here you can simply check the constraints afterwards.

    First solve your nonlinear system to get one/none/several solutions of the form (x,y). Then check which, if any, of these solutions, satisfy the constraints.