조회 수: 4(최근 30일)

표시 이전 댓글

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?

Thank you

Matt J
2021년 9월 9일

편집: Matt J
2021년 9월 9일

I've tried using fmincon with the same initial guesses as fsolve without success:

A simpler option than fmincon would be to use lsqnonlin, which is quite similar to fsolve except that it allows you to stipulate simple upper and lower bounds.

With the constraints, it's unable to find the solution because it gets stuck on a boundary.

Based on your description, I'm skeptical that the solver is "getting stuck". It sounds to me like the unconstrained solution really is outside the boundaries, and the constrained solution really is at the boundary. If I'm correct, tweaking the search mechanism will not help. Your equations themselves are the problem. There is some error or physical information lacking in the equations that would lead to a solution in the expected region.

One way to verify this would be to sample your equation function on a grid covering the bounded region. This is something that should be computationally tractable since you have only 3 unknowns. This will let you inspect directly where the solution lies (to within the resolution of the sampling grid).

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!