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 个评论
Swastik Sarkar
2024-8-28
编辑:Swastik Sarkar
2024-8-28
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
2024-9-2
Hi @Hammed
Can you please share the 'fccuStateFcnCT'and 'fccuOutputFcn' functions for better analysis?
Sandeep Mishra
2024-9-5
Hi @Hammed
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.
Sandeep Mishra
2024-9-5
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
2024-9-5
Hammed
2024-9-5
Sandeep Mishra
2024-9-5
Yes, I ran the MNPC code in matlab environment before running the simulink code and I am using MATLAB 2024a.
Sandeep Mishra
2024-9-5
In which version of MATLAB are you encountering the 'Error using sqpInterface' issue? What error message did you receive in MATLAB 2024a?
Hammed
2024-9-5
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Nonlinear MPC Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!