Dealing with Error "Not enough Input Arguments" when using NONLCON for fmincon
5 views (last 30 days)
Show older comments
Hello,
I'm trying to solve a basic non linear programming problem. It involves several non linear inequality constraints. I keep getting the error "Not enough input arguments" in the function fun3 whenever I try to run my full script. I'm new to matlab, so I know it is probably something very simple but I am stumped. Also, I probably misused the terminology in this post and I apologize.
Here is my code:
%%main function
clc
clear
tic
Budget=(1000:1000:5000);
SI=(100:100:1000);
ST=(10:10:100);
SA=(10:10:100);
Elapsed_Time=zeros(5,10,10,10);
for b=1:5
TBudget=Budget(b);
for i=1:10
si=SI(i);
for j=1:10
st=ST(j);
for k=1:10
sa=SA(k);
stime=zeros(st,sa);
x=zeros(st,sa);
y=zeros(2*st,2*sa);
target_recovery=0.3;
beta_l1=0.4;
beta_l2=0;
beta_l3=0.5;
alpha_r1=0.05;
alpha_r2=0.5;
alpha_r3=0.05;
alpha_r4=0.3;
delta_scost=0.3;
beta_cost=5;
lower_scost=6;
delta_ptime=5;
u=0.7;
upper_ptime=8;
lower_bound=0;
upper_bound=1;
p=0;
q=0.003;
for l=1:st
for m=1:sa
lb=zeros(2*st,sa);
ub=ones(2*st,sa);
for n=1:si
[cost(l,m),recovery_function(l,m),loss_function(l,m),ptime(l,m),ctime(l,m),quality_response_function(l,n,m)]=fun2(stime(l,m),x(l,m),delta_scost,beta_cost,lower_scost,alpha_r1,alpha_r2,alpha_r3,alpha_r4,beta_l1,beta_l2,beta_l3,upper_ptime,delta_ptime,u,p,q);
y(l,m)=stime(l,m);
y(st+l,m)=x(l,m);
end
end
rtim=min(ctime(l,:));
end
dec1(:,1)=sum((recovery_function-loss_function),2);
dec1(:,2)=sum(cost,2);
dec1(:,3:2+si)=sum(quality_response_function,3);
%optimal solution
y=fmincon(@fun1,rand(st,sa),[],[],[],[],lb,ub, fun3);
end
end
end
end
toc
%%fun1
function f=fun1(rtim)
obj=sum(rtim,2);
f=obj(1);
%%fun2
function [cost,recovery_function,loss_function,ptime,ctime,quality_response_function]=fun2(stime,x,delta_scost,beta_cost,lower_scost,alpha_r1,alpha_r2,alpha_r3,alpha_r4,beta_l1,beta_l2,beta_l3,upper_ptime,delta_ptime,u,p,q)
cost= delta_scost*exp(-beta_cost*x)+lower_scost + x;
recovery_function=alpha_r1*(1-alpha_r2*stime)+alpha_r3*(1-exp(-alpha_r4*x));
loss_function=beta_l1*(1+beta_l2*stime)*exp(-beta_l3*x);
ptime=upper_ptime-delta_ptime*(1-exp(-u*x));
ctime=stime+ptime;
quality_response_function= p*stime + q*x;
%%fun3
function [c,ceq]=fun3(dec1,TBudget,st,si)
c=[-dec1(:,1)+0.3*ones(st,1);
dec1(:,2)-TBudget*ones(st,1);
-dec1(:,3:(si+2));
dec1(:,3:(si+2))-ones(st,si)];
ceq=[];
Thank you!
0 Comments
Answers (2)
Alan Weiss
on 8 Dec 2014
In addition to what Matt J said, your nonlinear constraint function needs to be a function of one input variable. Either take the function as a function of dec1 alone:
@(dec1)fun3(dec1,TBudget,st,si)
or, if you have all four variables in the problem, bundle them into a new variable x as follows:
function [c,ceq]=fun3(x)
dec1 = x(1);
TBudget = x(2);
st = x(3);
si = x(4);
...
Alan Weiss
MATLAB mathematical toolbox documentation
Matt J
on 6 Dec 2014
Edited: Matt J
on 6 Dec 2014
You need to pass '@fun3' instead of just 'fun3':
y=fmincon(@fun1,rand(st,sa),[],[],[],[],lb,ub, @fun3);
2 Comments
Matt J
on 9 Dec 2014
It is the answer to your question, however. The error message that you posted "Not enough input arguments..." and which was the basis for your posted question was due to that.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!