Hi! I am trying to minimise a self-written objective function called optim_caps using patternsearch method And it is giving me this error .
Not enough input arguments.
Error in optim_caps (line 40)
[t,C] = ode23tb(@equations6,(0:tfinal),Cinit,options,para_cap,time_Flpurge_exp,Flpurge);
Error in funevaluate (line 54)
f = feval(FUN,reshapeinput(Xin,X),varargin{:});
Error in poptimfcnchk (line 23)
[y,count,cache] = funevaluate(FUN,Xin,X,'init',cache,[],[],objFcnArg{:});
Error in patternsearch (line 262)
[Iterate,OUTPUT.funccount] = poptimfcnchk(FUN,nonlcon,X0,Iterate, ...
Error in capillary_model_complete_recycling_calibration_model (line 38)
[para_cap,fval,exitflag,output]=patternsearch(@optim_caps,initial,[],[],[],[],lb,ub,[])
Caused by:
Failure in initial user-supplied objective function evaluation. PATTERNSEARCH cannot continue.
This is the declaration of my objective function. para_cap are the paramemters that I want to optimize, and the rest are just input
function ff =optim_caps(para_cap,Cgout_exp,CO2_exp_gm3,time_exp,time_exp_CO2,time_Flpurge_exp,Flpurge)
Inside my objective function I solve a ODE system and this is the declaratino of the ODE
[t,C] = ode23tb(@equations6,(0:tfinal),Cinit,options,para_cap,time_Flpurge_exp,Flpurge);
Equations6 is where I define my differential equations, and this is the definition of it:
function dC=equations6(t,C,para_cap,time_Flpurge_exp,Flpurge)
My question is, there is any specific data that should I extract from the patternsearch method that I am not feeding to my ODE solver? I feel I am missing some understanding on the syntaxis of the patternsearch.

 Accepted Answer

Walter Roberson
Walter Roberson on 30 Jul 2019

0 votes

https://www.mathworks.com/help/matlab/math/parameterizing-functions.html

3 Comments

Hi Walter,
could you please give me more especific details about how could I solve this issue. I would really appreciate it. thank you!
Change
[para_cap,fval,exitflag,output]=patternsearch(@optim_caps,initial,[],[],[],[],lb,ub,[])
to
obj = @(para_cap) optim_caps(para_cap, Cgout_exp, CO2_exp_gm3, time_exp, time_exp_CO2, time_Flpurge_exp, Flpurge);
[para_cap,fval,exitflag,output]=patternsearch(obj,initial,[],[],[],[],lb,ub,[])
The variables Cgout_exp, CO2_exp_gm3, time_exp, time_exp_CO2, time_Flpurge_exp, Flpurge will need to exist in the workspace of the function at the time the anonymous function is created.
Thank you very much Walter, your answer solved my problem. I really appreaciate it!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!