Restrain fsolve and fzero to return only postivie solutions

11 visualizaciones (últimos 30 días)
Dimitrios Kampitsis
Dimitrios Kampitsis el 17 de Feb. de 2022
Respondida: Torsten el 17 de Feb. de 2022
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.

Respuestas (1)

Torsten
Torsten el 17 de Feb. de 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.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by