how to add a constraint condition to fsolve?
Show older comments
Hi everyone,
These days I want to solve a system of nonlinear equations with matlab. In the equations, there are all four unkonwns, A(1),A(2),A(3)and A(4) to be solved but only three equations. therefore, the 'levenberg-marquardt' algorithm is applied to get the results. However, for physical meaning, an additional constraint is required, i.e. A(3)should be larger than zero. and with the 'levenberg-marquardt' algorithm, in the the obtained result, A(3) is negative.
Does anyone know how to add this constraint condition to fsolve ? Your help will be highly appreciated!
Accepted Answer
More Answers (3)
Sean de Wolski
on 19 Nov 2013
1 vote
fsolve does not provide the ability to use constraints. You'll need fmincon for this.
However, for physical meaning, an additional constraint is required, i.e. A(3)should be larger than zero.
If your constraints are simply non-negativity and bound constraints, you should probably use lsqnonlin. lsqnonlin is a bit more specialized than fmincon, and there may be advantages to that.
lsqnonlin is also set up to take exactly the same objective function format as fsolve, whereas fmincon doesn't.
Alan Weiss
on 20 Nov 2013
1 vote
Alan Weiss
MATLAB mathematical toolbox documentation
1 Comment
Diptangshu Paul
on 11 Dec 2025
Right, lsqnonlin is a great improvement over the existing strengths of fsolve.
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!