Non-negativity for unconstrained nonlinear multivariable function

2 views (last 30 days)
I don't have any constraint for my nonlinear problem, so I am using either fminsearch or fminunc. If I want to get only positive solutions, am I still able to use fminsearch or fminunc? If so, how can I do that?
Thanks,

Answers (3)

Sean de Wolski
Sean de Wolski on 18 Jun 2012
You probably could, but it is not ideal. fmincon() will be your friend, though.
More per follow up Here are two ways to do it:
f = @(x)x(1)+x(2); %function with a minimum @ [-inf -inf]
A = [-1 0; 0 -1]; %-x(1);-x(2);
b = [0;0]; %less than zero, i.e. negative x<0
fmincon(f,[pi pi],A,b) %go!
%or
fmincon(f,[pi pi],[],[],[],[],zeros(1,2),inf(1,2)) %lower bound at zero, upper at infinity
Welcome to MATLAB Answers!

Jalali
Jalali on 18 Jun 2012
Thanks! How do you define non-negativity for constraints in fmincon? Would you give me a simple example?

Sargondjani
Sargondjani on 18 Jun 2012
if you want your inputs to be positive, just add them as a lower bound, see documention. For example if your x is a vector of three then just add: lb=zeros(3,1);
if the objective has to be positive you have to put in an nonlinear constraint, see also documention. Basically you repeat the objective and set Cineq = -function_objective (the constraint is Cineq<=0)

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!