Hi all
I am trying to minimize the objective function over (x(1),x(2)):
exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1)+b
subject to constraint
(x(1))^2+x(2)-1+b=0, (notice that b is also in constraint)
-x(1)*x(2)-10<=0.
I want to run the optimization 20 times , for b=1, b=2, b=3.....b=20 ( because b is between 0 to 20). I also want to store the optimal (x(1),x(2),b) so that I can plot it later.
There are existing reference ((<http://www.mathworks.com/help/optim/ug/nonlinear-equality-and-inequality-constraints.html)>) which I followed. How do I modify the following code so that it will do the above?
Step 1: Write a file objfun.m.
function f = objfun(x)
f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1)+b;
Step 2: Write a file confuneq.m for the nonlinear constraints.
function [c, ceq] = confuneq(x)
c = -x(1)*x(2) - 10;
ceq = x(1)^2 + x(2) - 1+b;
Step 3: Invoke constrained optimization routine.
x0 = [-1,1];
options = optimoptions(@fmincon,'Algorithm','sqp');
[x,fval] = fmincon(@objfun,x0,[],[],[],[],[],[],...
@confuneq,options);