MultiStart with lsqcurvefit error: FUN must have two input arguments
50 ビュー (過去 30 日間)
古いコメントを表示
Hello folks,
I'm trying to fit a nonlinear curve from solving the advection-diffusion-adsorption PDE equation.
%Initial condition
IC=zeros(1,Nz)+1E-9;
%Initial guess
Lamdag=0.51;Kfg=1.0E+4;Ng=0.65;
g=[Lamdag;Kfg;Ng];
lb=[0.5,1E+3,0.3];
ub=[0.9,1E+5,1];
[P,SSE]=lsqcurvefit(@fun2,g,time,conc,lb,ub,[],IC,eps,V,De,Nz,dz,Cw,Jw);
I can use lsqcurvefit to fit my experimental data to the PDE eqaution and get the values of parameters successfuly. But it does not fit very well and I would like to try to use MultiStart to find the global optimization.
Therefore, I followed the example from this website https://www.mathworks.com/help/gads/multistart-using-lsqcurvefit-or-lsqnonlin.html. My script for the MultiStart is below:
problem = createOptimProblem('lsqcurvefit','x0',g,'objective',@fun2,...
'lb',lb,'ub',ub,'xdata',time,'ydata',conc); %lsqcurvefit
ms=MultiStart('PlotFcn',@gsplotbestf);
[x,fval,eflag,output,manymins]=run(ms,problem,50);
And I got the error: Error using lsqcurvefit (line 229)
FUN must have two input
arguments.
Error in globaloptim.multistart.fmultistart
Error in MultiStart/run (line 257)
globaloptim.multistart.fmultistart(problem,startPointSets,msoptions);
Error in DNP_NF270_fit (line 72)
[x,fval,eflag,output,manymins]=run(ms,problem,50);
Caused by:
Failure in call to the local solver with supplied problem structure.
I have searched the similar questions other people have asked and did not found what to do for my case. I have attached my .m script in the attachment if anyone need it.
Very appreciated if anyone can help me diagnose the problem. Thank you very much.
0 件のコメント
採用された回答
Torsten
2022 年 5 月 20 日
problem = createOptimProblem('lsqcurvefit','x0',g,'objective',@(p,xdata)fun2(p,xdata,IC,eps,V,De,Nz,dz,Cw,Jw),...
'lb',lb,'ub',ub,'xdata',time,'ydata',conc); %lsqcurvefit
4 件のコメント
Torsten
2022 年 5 月 22 日
Since you don't call "lsqcurvefit" directly by using
[P,SSE]=lsqcurvefit(@fun2,g,time,conc,lb,ub,[],IC,eps,V,De,Nz,dz,Cw,Jw);
how should MATLAB know by the setting
problem = createOptimProblem('lsqcurvefit','x0',g,'objective',@fun2,...
'lb',lb,'ub',ub,'xdata',time,'ydata',conc); %lsqcurvefit
that you also want to supply IC,eps,V,De,Nz,dz,Cw,Jw in the function "fun2" ?
Every time the actual list of input parameters to a function differs from the list MATLAB expects, you have to use
[P,SSE]=lsqcurvefit(@fun2,g,time,conc,lb,ub,[],IC,eps,V,De,Nz,dz,Cw,Jw);
or better
[P,SSE]=lsqcurvefit(@(p,xdata)fun2(p,xdata,IC,eps,V,De,Nz,dz,Cw,Jw),g,time,conc,lb,ub,[]);
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!