필터 지우기
필터 지우기

The code for nmpc is not working even if i put it in same folder ?

조회 수: 3 (최근 30일)
AMAN
AMAN 2023년 10월 22일
댓글: AMAN 2023년 10월 23일
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
n1 =
nlmpc with properties: Ts: 0.2500 PredictionHorizon: 400 ControlHorizon: 50 Dimensions: [1×1 struct] Model: [1×1 struct] States: [1×4 struct] OutputVariables: [1×2 struct] ManipulatedVariables: [1×2 struct] MeasuredDisturbances: [] Weights: [1×1 struct] Optimization: [1×1 struct] Jacobian: [1×1 struct] Passivity: [1×1 struct]
%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]
x0 = 4×1
10 15 13 15
u=[5;07]
u = 2×1
5 7
validateFcns(n1,x0,u)
Error using nlmpc/validateFcns
Function statefunctiontank does not exist.
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.

채택된 답변

Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023년 10월 23일
I wasn't able to reproduce the error. Both state and output functions must be in different .m files. I did that and put everything on the same folder and did not get the error you are seeing (once you get it to work you will get a different error because you need to transpose the output dimensions of the state function).
  댓글 수: 5
Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023년 10월 23일
The error looks self-explanatory - take a look at the definition of the output function and make sure it's consistent with what the nlmpc object requires. Looks like there should be one more argument in there. This page provides more information on how to define state and output functions:
AMAN
AMAN 2023년 10월 23일
I Got it now thank you for your help very much sir.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Model Predictive Control Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by