Error when running simulation

i need help in solving the error i got when runing the simulation;
Error using sqpInterface
Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 900)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = sqpInterface(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
Error in nlmpc/nlmpcmove (line 174)
[z, cost, ExitFlag, Out] = fmincon(CostFcn, z0, A, B, [], [], zLB, zUB, ConFcn, fminconOpt);
Error in nmpcblock_interface (line 163)
[mv, ~, Info] = nlmpcmove(nlobj, x, lastmv, ref, md, Options);
------------------------------------------------------
End of Error Report
------------------------------------------------------
the code bellow is the NMPC code
clc, clear all
%% Simulink Model
% To run this example, Simulink(R) is required.
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink is required to run this example.')
return
end
%%initialize NMPC object and set properties
nx = 12;
ny = 6;
nlobj = nlmpc(nx, ny, 'MV', [1,2,3,4], 'UD', [5,6,7,8,9,10]);
%The prediction model sample time is the same as the controller sample time
Ts = 2;
nlobj.Ts = Ts;
%Prediction and control horizon
nlobj.PredictionHorizon = 12;
nlobj.ControlHorizon = 2;
%weights on output and manipulated variables
nlobj.Weights.OutputVariables = [100,100,100,100,100,100];
nlobj.Weights.ManipulatedVariables = [1,1,1,1];
nlobj.Weights.ManipulatedVariablesRate = [0.1,0.1,0.1,0.1];
%constraints on manipulated variables
nlobj.MV(1).RateMin = -200;
nlobj.MV(2).RateMin = -150;
nlobj.MV(3).RateMin = -10;
nlobj.MV(4).RateMin = -150;
nlobj.MV(1).RateMax = 200;
nlobj.MV(2).RateMax = 150;
nlobj.MV(3).RateMax = 10;
nlobj.MV(4).RateMax = 150;
nlobj.MV(1).Min = 1500;
nlobj.MV(2).Min = 1300;
nlobj.MV(3).Min = 400;
nlobj.MV(4).Min = 12400;
nlobj.MV(1).Max = 2600;
nlobj.MV(2).Max = 2000;
nlobj.MV(3).Max = 600;
nlobj.MV(4).Max = 13200;
%constraint on output variables to keep them within reasonable bounds
nlobj.OV(1).Min = 0;
nlobj.OV(2).Min = 920;
nlobj.OV(3).Min = 0.85;
nlobj.OV(4).Min = 0;
nlobj.OV(5).Min = 0;
nlobj.OV(6).Min = 770;
nlobj.OV(1).Max = 0.02;
nlobj.OV(2).Max = 935;
nlobj.OV(3).Max = 1.25;
nlobj.OV(4).Max = 0.02;
nlobj.OV(5).Max = 0.02;
nlobj.OV(6).Max = 800;
%% specify the nonlinear state and output functions
nlobj.Model.StateFcn = 'fccuStateFcnCT';
nlobj.Model.OutputFcn = 'fccuOutputFcn';
%% validate the nonlinear MPC object with initial conditions
y0 = [0.002156;427.2; 0.2136; 0.03598; 0.002156; 449.3; 0; 0; 0; 0; 0; 0];
u0 = [2080; 1720; 503; 13028];
validateFcns(nlobj, y0, u0);

12 commentaires

Torsten
Torsten le 19 Août 2024
Modifié(e) : Torsten le 19 Août 2024
Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.
Before starting the simulation, call "ConFcn" with your initial vector z0. Most probably, something undefined will be returned. At least that's what the error message says.
Swastik Sarkar
Swastik Sarkar le 28 Août 2024
Modifié(e) : Swastik Sarkar le 28 Août 2024
I attempted to run the code you provided, but encountered a different error than the one you specified
Error using nlmpc/validateFcns (line 179)
Function fccuStateFcnCT does not exist.
Is there any additional information or configuration I need to specify before executing this script?
Sandeep Mishra
Sandeep Mishra le 2 Sep 2024
Can you please share the 'fccuStateFcnCT'and 'fccuOutputFcn' functions for better analysis?
Hammed
Hammed le 4 Sep 2024
Modifié(e) : Hammed le 5 Sep 2024
@Sandeep Mishra @Swastik Sarkar thanks for your response. I try to modify the simulation to control 4 output instead of 6 that i was trying to do earlier, i will upload the code below, though i am still experencing the same issue
NMPC code
clc, clear all
%% Simulink Model
% To run this example, Simulink(R) is required.
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink is required to run this example.')
return
end
%%initialize NMPC object and set properties
nx = 6;
ny = 4;
%'UD', [5,6,7,8,9,10]
nlobj = nlmpc(nx, ny, 'MV', [1,2,3,4]);
%The prediction model sample time is the same as the controller sample time
Ts = 2;
nlobj.Ts = Ts;
%Prediction and control horizon
nlobj.PredictionHorizon = 10;
nlobj.ControlHorizon = 2;
%weights on output and manipulated variables
nlobj.Weights.OutputVariables = [1000,1000,1000,1000];
nlobj.Weights.ManipulatedVariables = [0.01,0.01,0.01,0.01];
nlobj.Weights.ManipulatedVariablesRate = [100,100,100,100];
%constraints on manipulated variables
nlobj.MV(1).RateMin = -200;
nlobj.MV(2).RateMin = -150;
nlobj.MV(3).RateMin = -10;
nlobj.MV(4).RateMin = -150;
nlobj.MV(1).RateMax = 200;
nlobj.MV(2).RateMax = 150;
nlobj.MV(3).RateMax = 10;
nlobj.MV(4).RateMax = 150;
nlobj.MV(1).Min = 1500;
nlobj.MV(2).Min = 1300;
nlobj.MV(3).Min = 400;
nlobj.MV(4).Min = 12400;
nlobj.MV(1).Max = 2600;
nlobj.MV(2).Max = 2000;
nlobj.MV(3).Max = 600;
nlobj.MV(4).Max = 13200;
%constraint on output variables to keep them within reasonable bounds
nlobj.OV(1).Min = 0;
nlobj.OV(2).Min = 920;
nlobj.OV(3).Min = 0.85;
nlobj.OV(4).Min = 770;
nlobj.OV(1).Max = 50;
nlobj.OV(2).Max = 935;
nlobj.OV(3).Max = 1.25;
nlobj.OV(4).Max = 800;
%% specify the nonlinear state and output functions
nlobj.Model.StateFcn = 'fccuStateFcnCT';
nlobj.Model.OutputFcn = 'fccuOutputFcn';
%% validate the nonlinear MPC object with initial conditions
y0 = [0.002156;427.2; 0.2136; 0.03598; 0.002156; 449.3];
u0 = [2080; 1720; 503; 13028];
validateFcns(nlobj, y0, u0);
fccuStateFcnCT
function dydt = fccuStateFcnCT(y, u)
%definig the parameters
deltaHfv = 498;
deltaHcr = 506;
deltaHrg = -394200;
cpo = 3.1335;
cpa = 1.074;
cps = 1.005;
sf = 14.57;
sc = 787.9601;
Ecc = 41.79;
Ecr = 101.5;
Ecb = 158.6;
Din = 915.1;
R = 0.0083143;
%kfo = 0.8;
kcc = 0.0189;
kcr = 19620;
Oin = 0.2136;
kcb = 187940;
ksig = 0.1197;
alpha = 0.12;
Vc = 175738;
Va = 20;
Pris = 100000;
Vris = 2500;
%Frc = 13028;
%Fin = 1720;
%Fa = 2080;
%Toil = 503;
Ta = 298;
%yf0 = 0.8;
%tc = 1.453;
%phi = 0.724;
%%% state parameters
Crc = y(1);
Treg = y(2);
Ofg = y(3);
Ccat = y(4);
Csc = y(5);
Tris = y(6);
%%% input parameters
Fa = u(1);
Fin = u(2);
Toil = u(3);
Frc = u(4);
dydt = zeros(6,1);
dydt(1) = ((Frc*(Csc - Crc))/Vc) - kcb*Ofg*Crc*exp(-Ecb/(R*(Treg+510)));
dydt(2) = ((Frc*(Tris - Treg))/Vc) + (((cpa/cps)*Fa*(Ta - Treg)))/(Vc) + ((-deltaHrg*kcb*Ofg*Crc*(exp(-Ecb/(R*Treg)))))/(sf);
dydt(3) = ((0.0313*Fa*(Oin - Ofg)))/(Va) - (ksig*kcb*Ofg*Crc*(Vc/Va)*exp(-Ecb/(R*(Treg+510))));
dydt(4) = (-Frc*Ccat/Vris) + (kcc*Pris*exp(-Ecc/(R*(Tris- 60)))/((Ccat*Crc^0.06)));
dydt(5) = Frc*(Crc - Csc)/Vris + kcc*Pris*exp(-Ecc/(R*(Tris- 60))/(Ccat*Crc^0.06));
Kr = kcr*exp(-Ecr/R*(Tris - 60))/(Ccat*Crc^0.15);
dydt(6) = (Frc*(Treg - Tris))/(Vris) + (cpo/(cps*Vris))*Fin*(Toil - Tris) + (0.875*(-deltaHfv*Fin))/(sc*Vris) + (-deltaHcr*Pris*Din*Fin*Kr)/(2*sc*(Fin + 0.0313*Vris*Pris*Din*Kr));
fccuOutputfcn
function k = fccuOutputFcn(y, u)
kcr = 19620;
Ecr = 101.5;
R = 0.0083143;
Frc = u(4);
Fin = u(2);
Tris = y(6);
Ccat = y(4);
Crc = y(1);
alpha = 0.12;
yf0 = 0.8;
phi = 0.724;
tc = 1.453;
Kr = kcr*exp(-Ecr/R*(Tris - 60))/(Ccat*Crc^0.15);
COR = Frc/Fin;
yf = (alpha*yf0)/(alpha + Kr*phi*(1 - exp(-alpha*tc*COR)));
k = [yf;y(2);y(3);y(6)];
fccuMeasFcn code
function k = fccuMeasFcn(y, u)
kcr = 19620;
Ecr = 101.5;
R = 0.0083143;
Frc = u(4);
Fin = u(2);
Tris = y(6);
Ccat = y(4);
Crc = y(1);
alpha = 0.12;
yf0 = 0.8;
phi = 0.724;
tc = 1.453;
Kr = kcr*exp(-Ecr/R*(Tris - 60))/(Ccat*Crc^0.15);
COR = Frc/Fin;
yf = (alpha*yf0)/(alpha + Kr*phi*(1 - exp(-alpha*tc*COR)));
k = [yf;y(2);y(3);y(6)];
Sandeep Mishra
Sandeep Mishra le 5 Sep 2024
I tried running your simulink file and found there exist one more function 'fccuStateFcnDT' required to run the simulation.
Are you treating the 'fccuStateFcnCT' function same as 'fccuStateFcnDT' function? If i do so, then i am getting error of signal dimension mismatch at Mux6.
Hammed
Hammed le 5 Sep 2024
Modifié(e) : Hammed le 5 Sep 2024
@Sandeep Mishra @Swastik Sarkar thanks for the response, i forgot to upload the fccuStateFcnDT, i am not treating it as fccuStateFcnDT,
fccuStateFcnDT code is uploaded below;
function yk1 = fccuStateFcnDT(yk,uk)
hstep = 1;
yk1 = yk(:);
Nsteps = 2;
uk1 = [uk(:)];
for i = 1:Nsteps
yk1 = yk1 + hstep*fccuStateFcnCT(yk1,uk1);
end
i will be awaiting your response
Sandeep Mishra
Sandeep Mishra le 5 Sep 2024
When I run the Simulink file after executing the script and adding all the functions, I get the following error:
Error:Invalid setting for output port dimensions of 'fccu_2023b_4_output/Mux6'. The dimensions are being set to 1. This is not valid because the total number of input and output elements are not the same
Error:Error in port widths or dimensions. 'Input Port 1' of 'fccu_2023b_4_output/Zero-Order Hold' is a one dimensional vector with 1 elements.
Am I missing something or doing something wrong?
Hammed
Hammed le 5 Sep 2024
Thanks for the response, what version of matlab are you using?? besides, did you run the MNPC code in matlab environment before running the simulink code?
Hammed
Hammed le 5 Sep 2024
i was having same issue with matlab2024a but i was unable to resolve it, but it worked on 2023b. So i had to install 2023b
Sandeep Mishra
Sandeep Mishra le 5 Sep 2024
Yes, I ran the MNPC code in matlab environment before running the simulink code and I am using MATLAB 2024a.
Sandeep Mishra
Sandeep Mishra le 5 Sep 2024
In which version of MATLAB are you encountering the 'Error using sqpInterface' issue? What error message did you receive in MATLAB 2024a?
Hammed
Hammed le 5 Sep 2024
Thanks for your response.
i am receiving 'Error using sqpInterface' issue in 2023b but i am reciving this particular error in 'Error:Invalid setting for output port dimensions of 'fccu_2023b_4_output/Mux6'. The dimensions are being set to 1. This is not valid because the total number of input and output elements are not the same
Error:Error in port widths or dimensions. 'Input Port 1' of 'fccu_2023b_4_output/Zero-Order Hold' is a one dimensional vector with 1 elements.' in 2024a that is why i switched to 2023b

Connectez-vous pour commenter.

Réponses (0)

Catégories

Produits

Version

R2024a

Question posée :

le 19 Août 2024

Modifié(e) :

le 5 Sep 2024

Community Treasure Hunt

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

Start Hunting!

Translated by