why validateFcns is not working in my nlmpc Code?
Show older comments
For your convinence i have attached the requird files that will save the copy paste time
% Parameters of SIRC model
n1=nlmpc(4,4,1);
n1.PredictionHorizon=100;
n1.ControlHorizon=10;
n1.Ts=1;
n1.Model.StateFcn="sircstatefcn";
n1.Model.OutputFcn="sircoutput";
S0 = 0.1; % Initial susceptible population
I0 = 0.3; % Initial infected population
R0 = 0.5; % Initial recovered population
C0 = 0.1;
x0 = [S0, I0, R0, C0]; % Initial conditions
u0=0.2;
validateFcns(n1,x0,u0)
function dx = sircstatefcn(x,u,p)
p.mu = 0.015;
p.alpha = 100;
p.delta = 0.625;
p.gamma = 0.30;
p.sigma= 0.1;
p.beta0 = 0.5;
fx=zeros(4,1);
fx(1)=p.mu*(1-x(1)) + p.gamma*x(4);
fx(2)= -(p.mu + p.alpha)*x(2);
fx(3)=p.alpha*x(2) - (p.mu + p.delta)*x(3);
fx(4)=p.delta*x(3) - (p.mu + p.gamma)*x(4);
gx=zeros(4,1);
gx(1)=-x(2)*x(1);
gx(2)=x(2)*x(1) + p.sigma*x(4)*x(2);
gx(3)=(1-p.sigma)*x(2)*x(4);
gx(4)=-x(4)*x(2);
dx=fx+gx*u;
%original state space model
% dx = [ p.mu*(1-x(1)) - u(1)*x(2)*x(1) + p.gamma*x(4);
% u(1)*x(2)*x(1) + p.sigma*u(1)*x(4)*x(2) - (p.mu + p.alpha)*x(2);
% (1-p.sigma)*u(1)*x(2)*x(4) + p.alpha*x(2) - (p.mu + p.delta)*x(3);
% p.delta*x(3) - u(1)*x(4)*x(2) - (p.mu + p.gamma)*x(4)];
dx=dx';
end
function y= sircoutput(x,u)
y(1)=x(1);
y(2)=x(2);
y(3)=x(3);
y(4)=x(4);
y=y';
end
Please copy both function and make seperate code files for them and then make seperate file for nlmpc evaluation and then execute the code.You will see the required error i was gettin which is ---------------------------------------------------
Error using nlmpc/validateFcns
Expecting 2 input arguments but "Model.StateFcn" appears to take 3 inputs.
Error in nmpcseir (line 15)
validateFcns(n1,x0,u0)
Accepted Answer
More Answers (0)
Categories
Find more on Downloads 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!