How do I restrict the solution of ONLY ONE variable, of many other variables, to be between 0 and 1?

2 views (last 30 days)
Hi I have a system of 15 equations and 15 variables and am solving the system using FSOLVE. I'd like to restrict the solution of one (if possible two for future use) of the variables to be between 0 and 1. Your help is greatly appreciated!

Accepted Answer

John D'Errico
John D'Errico on 26 Mar 2015
Fsolve cannot apply constraints.
However, it is trivial to transform your problem so that it is constrained. Just transform that variable inside your objective, taking (sin(x)).^2 as fsolve passes it in. That number will always be in the interval [0,1], no matter what fsolve thinks it is.
Then when fzolve returns a result, apply the same transformation to that variable. It MAY have the effect of making your optimization more nonlinear (or less!) but it is a simple way to implement a constraint of that form.
And of course, you need to do the reverse transform to the starting value for that parameter, thus asin(sqrt(x0)).

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!