hi i am a matlab beginner and i am trying to use fmincon to solve a 2-dimensional optimization problem
there is always some error with the factorial part: (i set k as non-negative values but why still exists error?)
Error using factorial (line 20)N must be an array of real non-negative integers.Error in expectedprofit (line 19)denominator = h+k*power(rho,k)/[(k-rho)*factorial(k)];Error in fmincon (line 535) initVals.f = feval(funfcn{3},X,varargin{:});Error in main (line 9)x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub);Caused by: Failure in initial objective function evaluation. FMINCON cannot continue.
my function code is:
function [ y ] = expectedprofit(x)k = x(1);s = x(2);potential_arrival_rate=50;lambda=potential_arrival_rate*s;mu=1;c=20;K=1000;rho=lambda/mu;h=0;for t=0:k-1 h=h+power(rho,t)/factorial(t);end;denominator = h+k*power(rho,k)/[(k-rho)*factorial(k)];numerator = k*power(rho,k)/[(k-rho)*factorial(k)];C = numerator/denominator;waitingtime = C/[mu*(k-rho)];y=-lambda*[1-s-c*waitingtime-power(k,2)/(K*lambda)];end
and my fmincon code is:
fun = @expectedprofit;x0 = [1,0.1];A = [-1,100];b = 0;Aeq = [];beq = [];lb = [0,0];ub = [100,1];x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub);
Best Answer