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,
댓글 수: 0
답변 (3개)
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!
댓글 수: 0
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)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!