Non-negativity for unconstrained nonlinear multivariable function

2 次查看(过去 30 天)
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