Restrain fsolve and fzero to return only postivie solutions
4 views (last 30 days)
Show older comments
I am trying to solve some non linear equations, quite simply I would say, with fzero and fsolve. I get a solution but I would like to aquire only positve solutions, which they do exist. Is there a way to avoid negative solutions ?
I would like to note that I have tried fzero(fun,[xlower, xupper]) but unfortunately it doesn't work.
0 Comments
Answers (1)
Torsten
on 17 Feb 2022
In fzero or fsolve, square the x vector with which you are asked to evaluate your equation:
function res = fun(x)
x = x.^2;
...
res = ...
end
Then, when fzero or fsolve returns to the calling program, x.^2 solves your equations, and x.^2 is non-negative.
0 Comments
See Also
Categories
Find more on Optimization 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!