Block does not fully set the dimensions of output 'A'

215 ビュー (過去 30 日間)
Aleksandr Kashirin
Aleksandr Kashirin 2021 年 3 月 15 日
コメント済み: Ratchanon Iamsamang 2022 年 12 月 15 日
Hello!
I am trying to create an MPC controller according to the MATLAB guide (*https://www.youtube.com/watch?v=aQhpvrQPxD4&t=212s&ab_channel=MATLAB*).
I have already synthesyzed MPC controller for linearized system and now I want to create one for nonlinear system using the mpc controller I have already created.
Here is my problem:
Block ''Model_v1/Plant Model'' does not fully set the dimensions of output 'A'.
Component:Simulink | Category:Block error
Does anyone know how to fix this?
Here is my sctructure:
Here is code inside "Plant Model" function:
function [A,B,C,D,U,Y,X,DX] = fcn(u,x)
% Sample time
Ts = 0.01;
% Model parameters
M = 1000; % Cart mass, kg
m = 800; % Load mass, kg
L = 3; % Reduced rope and load length, m
g = 9.81; % Gravity constant, m/s^2
k_cart = 0.0113; % Rolling resistance coefficient
R = 0.1; % Cart wheel radius, м
% Continuos-time model
% Calculated constants
c1 = 1 - m/(m + M);
c2 = -1/(L*(m + M));
Ac = [0 1 0 0
0 -k_cart*(m + M)*g/M m*g/M 0
0 0 0 1
0 k_cart*g/(L*c1) -g/(L*c1) 0];
Bc = [ 0
1/M
0
c2/c1];
Cc = [1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1];
Dc = [0
0
0
0];
% Generate discrete-time model
nx = size(Ac,1);
nu = size(Bc,2);
Mr = expm([[Ac Bc]*Ts; zeros(nu,nx+nu)]);
A = Mr(1:nx,1:nx);
B = Mr(1:nx,nx+1:nx+nu);
C = Cc;
D = Dc;
% Nominal conditions for discrete-time plant
X = x;
U = u;
Y = C*x + D*u;
DX = A*x+B*u-x;

回答 (1 件)

Asvin Kumar
Asvin Kumar 2021 年 3 月 17 日
The first assignment to an output variable determines its size in MATLAB Function blocks. I suppose Simulink isn't able to infer the size of A from its assignment statement.
Two ideas/suggestions:
  1. Try initializing A to zeros(4,4) or as appropriate.
  2. Right click on the block, select Explore (first option in menu) which will open the Model Explorer. You can manually set the sizes of the input and output ports as required. The default size is -1 which means Simulink should try to inherit the size by looking at the code in the block.

カテゴリ

Help Center および File ExchangeLinear Plant Specification についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by