MultiStart with lsqcurvefit error: FUN must have two input arguments

57 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Torsten
Torsten am 20 Mai 2022
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 Kommentare
Zerui Hao
Zerui Hao am 22 Mai 2022
Thank you Alan. I try to use different finite difference steps and even using MultiStart. The fitting result is actually my intial guess, and it did not change at all. It's weired.
Torsten
Torsten am 22 Mai 2022
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,[]);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by