error using fmincon requiers following inputs to be of data type double: 'LB', 'UB'

2 次查看(过去 30 天)
Hi, I am facing this above error when I run my code, I have been trying to solve the coupled differential equations using ODE45 solver, the program runs well and good when I use lsqcurvefit, but i get back a warning for bound constraints so I thought I will run the code with fmincon as it could give a minimum of constrained nonlinear variables, but the issue is I am facing the above error in the code, what is the mistake I am doing here please suggest some suggestions to avoid the above error. Thank you in advance.
  3 个评论
dinesh kumar s
dinesh kumar s 2023-9-7
Hi thanks for reply, I am briefing what I have done in my work.
This is the output I get after using the class:
Error using fmincon
FMINCON requires the following inputs to be of data type double: 'LB'.
Error in Trial (line 31)
[theta0,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=fmincon(@kinetics,theta0,t,c,lb,ub,options);
The part of the code i am using:
theta0=[1,1e7,1e7,1e5,1e5,1e-80,1e-80]; % the initial parameters
lb=[1;1e6;1e6;1e4;1e1;1e-80;1e-80]; %lower bounds
ub=[+inf;1e8;1e8;1e8;1e8;1e-20;1e-15];%upper bounds
%options and fmincon
%options = optimoptions('lsqcurvefit','Algorithm','trust-region-reflective','StepTolerance',1e-20 , 'OptimalityTolerance', 1e-16, 'FunctionTolerance', 1e-20, 'MaxFunctionEvaluations', 100000, 'MaxIter', 50000);
%[theta0,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@kinetics,theta0,t,c,lb,ub,options);
options = optimoptions('fmincon','Algorithm','trust-region-reflective','ConstraintTolerance',1e-16 , 'OptimalityTolerance', 1e-16, 'FunctionTolerance', 1e-20, 'MaxFunctionEvaluations', 100000, 'MaxIter', 50000);
[theta0,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=fmincon(@kinetics,theta0,t,c,lb,ub,options);
tv = logspace(log10(0.02392e-6), log10(6.512e-6),10000);
Cfit = kinetics(theta0, tv);
function C=kinetics(theta,t)
c0=[1,0];
options = odeset('RelTol',1e-12,'AbsTol',1e-14);
[T,Cv]=ode45(@DifEq,t,c0,options);
function dC=DifEq(t,c)
dcdt=zeros(2,1);
dcdt(1)= theta(1)-(theta(2)+theta(3)).*c(1)+theta(4).*c(2)+0.25.*theta(6).*c(2).*c(2)-theta(7).*c(1).*c(2);
dcdt(2)= -(theta(4)+theta(5)).*c(2)+theta(3).*c(1)-1.25.*theta(6).*c(2).*c(2);
dC=dcdt;
end
C=Cv(:,1);
Basically, I have a set of data in time regime, I am trying to fit the data with a coupled differential equation using ODE solvers, when i use ODE45, i was kept getting a warning
I was using lsqcurvefit and ODE 45 for fitting the data, so because of this warning I am getting skeptical about the fitted parameters, that's why I thought of using fmincon instead of lsqcurvefit.
The following warning I get if I run the code with lsqcurvefit and ODE 45 solver:
Warning: Derivative finite-differencing step was artificially reduced to be within bound constraints.
This may adversely affect convergence. Increasing distance between bound constraints, in dimension 7, to
be at least 1.9973e-15 may improve results.
> In fwdFinDiffInsideBnds
In finitedifferences
In computeFinDiffGradAndJac
In sfdnls (line 54)
In snls (line 343)
In lsqncommon (line 180)
In lsqcurvefit (line 274)
In Trial (line 32)
Stephen23
Stephen23 2023-9-7
编辑:Stephen23 2023-9-7
The FMIINCON documentation
shows that LB and UB must be the 7th and 8th input arguments respectively. Instead of following the documentation, you have provided them as the 5th and 6th inputs. Inventing syntaxes will not work, you need to follow the documentation.
Note that the documentation explains that unspecified inputs e.g. AEQ, BEQ, LB, UB may be [].

请先登录,再进行评论。

回答(1 个)

Bruno Luong
Bruno Luong 2023-9-7
The low bound and up bounds must be 7th and 8th arguments of fmincon. You do not respect the argument list. Check thedoc fmincon

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by