I'm trying to use fsolve to solve a small nonlinear system (3 equations) for which I have constraints on the unknowns. I know I can't explicitely enforce constraints using fsolve, but I always have access to a good initial guess, which generally allows the solver to find the solution I need without looking outside the constraints boundaries.
However, changing the equation parameters (which I need to be able to do) sometimes results in fsolve trying to find a solution outside the boundaries, which is not acceptable.
I've tried using fmincon with the same initial guesses as fsolve without success: without applying constraints, it tends to search outside the constraints boundaries and make the solution crash faster than fsolve. With the constraints, it's unable to find the solution because it gets stuck on a boundary.
I'm thinking that if I could add some kind of relaxation in the fsolve algorithm, it could help me stay inside my constraints (without guarantees, of course). In other words, I'm trying to find if there's a way to limit the step size taken by fsolve from one iteration to another. I've found the following options in the documentation, but they do not do what I need:
- FiniteDifferenceStepSize: this allows to set the step size used to estimate the gradient inside a given fsolve iteration, but offers no control on the step taken on the solution vector from one iteration to another
- StepTolerance: this is a lower bound on the step size from one iteration to another (what I'm looking is an upper bound on that value)
Basically, I'd like fsolve to estimate the gradient, but let me decide how far along that gradient I want to go. Is there any other option, or even other solver I didn't think of that could do something like that?