Non-negativity for unconstrained nonlinear multivariable function

조회 수: 2 (최근 30일)
Jalali
Jalali 2012년 6월 18일
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,

답변 (3개)

Sean de Wolski
Sean de Wolski 2012년 6월 18일
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 2012년 6월 18일
Thanks! How do you define non-negativity for constraints in fmincon? Would you give me a simple example?

Sargondjani
Sargondjani 2012년 6월 18일
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)

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by