Monday, 15 September 2014

fminsearch - Matlab: finding the maximum point in for loop -



fminsearch - Matlab: finding the maximum point in for loop -

for 2 variable function, f(x,y)=x^2+y+b, b is:

b=raylrnd(1*sqrt(2/pi),10^6,1) %% b 1x1000000 vector

and subject constraint that: 2*x+1<=b.

i want find maximum of function interval x between [-10,10], , y between [-10,10] (off course, actual function more finish this, need help set framework can apply actual function).

is there way implement this?

attempt:

step 1: write file objfun.m.

function f = objfun(x,b) f = x(1)^2+(2)+b;

step 2: write file confuneq.m nonlinear constraints.

function [c, ceq] = confuneq(x) % nonlinear inequality constraints c = 2*x(1)+1-b;

step 3: invoke constrained optimization routine.

for i=1:1:length(b) bi=b(i); x0 = [-1,1]; % create starting guess @ solution options = optimoptions(@fmincon,'algorithm','sqp'); [x,fval] = fmincon(@objfun,x0,[],[],[],[],[],[],... @confuneq,options);

matlab fminsearch

No comments:

Post a Comment