Non-negativity for unconstrained nonlinear multivariable function
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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,
0 Commenti
Risposte (3)
Sean de Wolski
il 18 Giu 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!
0 Commenti
Sargondjani
il 18 Giu 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)
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!