The code for nmpc is not working even if i put it in same folder ?
Mostrar comentarios más antiguos
nx = 4; %no. of states
ny = 2; %no. of outputs
nu = 2; %no. of inputs
n1 = nlmpc(nx,ny,nu);
n1.Model.StateFcn="statefunctiontank";
n1.Model.OutputFcn="outputtank";
n1.PredictionHorizon=400;
n1.ControlHorizon=50;
Ts = 0.25;
n1.Ts = Ts
%setting constraints on states
n1.States(1).Max=40;
n1.States(1).Min=0;
n1.States(2).Max=40;
n1.States(2).Min=0;
n1.States(3).Max=40;
n1.States(3).Min=0;
n1.States(4).Max=40;
n1.States(4).Min=0;
%setting constraints on output
n1.Ov(1).Max=40;
n1.Ov(1).Min=0;
n1.Ov(2).Max=40;
n1.Ov(2).Min=0;
%setting constraints on input
n1.Mv(1).Max=10;
n1.Mv(1).Min=0;
n1.Mv(2).Max=10;
n1.Mv(2).Min=0;
%Validate model fucntion at arbitrary point
x0=[10;15;13;15]
u=[5;07]
validateFcns(n1,x0,u)
function dxdt= statefunctiontank(x,u)
A1 = 28;
A2 = 32;
A3 = 28;
A4 = 32;
a1 = 0.071;
a2 = 0.057;
a3 = 0.071;
a4 = 0.057;
gamma1 = 0.70;
gamma2 = 0.60;
g = 981;
dxdt(1) = -a1/A1*sqrt(2*g*x(1)) + a3/A1*sqrt(2*g*x(3))+(gamma1/A1)*u(1);
dxdt(2) = -a2/A2*sqrt(2*g*x(2)) + a4/A2*sqrt(2*g*x(4))+(gamma2/A2)*u(2);
dxdt(3) = -a3/A3*sqrt(2*g*x(3)) + ((1-gamma2)/A3)*u(2);
dxdt(4) = -a4/A4*sqrt(2*g*x(4)) + ((1-gamma1)/A4)*u(1);
end
function [y] = outputtank(x)
y=[x(1);x(2)];
end
these functions i was using as different code and called these in above code but i was not able to get what i should do to correct it.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Model Predictive Control Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
