how to fix an error:'' error in port widths or dimensions.''

56 次查看(过去 30 天)
Hello everyone,
I made a state space representation with disturbances using blocks in simulink, then I connected this state space to model predictive control, and when I run the system it gives an error as shown below: the red spot in the figure is where the error is,
and my state space model is as follow:
so A, B, C and D and Bd should be correct as I made them, right?
  3 个评论
jana nassereddine
jana nassereddine 2023-4-13
Hi Daniel,
thanks a lot for your help, for C and D, I forgot to mention that the ouput is the same as the states, so C=A and D=0;
and I corrected A and C, but I didn't really understand the last part of matrix multiplication, could you explain it to me even futher please?
by the way, u and y are included in the model predictive control, so should I mention something about their dimension, and if yes how?
Daniel
Daniel 2023-4-14
Thanks for the screenshots with dimensions. They help a lot.
Let's start by discussing the state space equations. You've got a column vector output: 2 rows by 1 column. So the inputs Ax(n) and Bu(n) should both be 2x1.
Presuming that your input ref is supposed to be the same dimensionality as your output mv, you're currently driving a 1x2 row vector rather than a 2x1 column vector. That will throw off the state space in your plant model.
Now to discuss the different multiplication options...
In MATLAB we have a few different ways of multiplying, which Simulink mimics, following standard linear algebra techniques.
First method: Elementwise
If you have a matrix A, of dimension , and you want to multiply each element in A by the matching element in a matrix B, then you can do that as:
A = rand(2,3) % Create a 2x3 matrix A
A = 2×3
0.7650 0.2530 0.2346 0.8413 0.9868 0.0356
B = rand(2,3) % Create a matrix B of the same dimensionality
B = 2×3
0.9897 0.6145 0.6273 0.0900 0.5769 0.7224
C = A.*B % Multiply each element by the corresponding element with .*
C = 2×3
0.7571 0.1555 0.1472 0.0757 0.5693 0.0257
This is what Simulink does by default.
Second and third methods: K*u and u*K
If you want to do a matrix multiplication on A (see this simple explanation or this more formal explanation), then how you're multiplying by the Gain block constant (K) matters. For matrix multiplication, the two inputs A and B can have different sizes, following this rule:
For A having dimension and B having dimension , requires and produces an output with dimension .
Back to the gain block
So if you use elementwise multiplication in your Gain block A, your (presumably) 2x1 Integrator output will be multiplied by a 2x2 matrix A. Simulink can't perform elementwise multiplication unless the two arrays have the same dimensionality, so it will fail. This applies to the other gain blocks in the design as well. You'll want to left-multiply: K*u.
One more thing. You will have to set the initial conditions in the integrator to a 2x1 vector as well. Otherwise your integrator doesn't know what dimensionality it's supposed to have.
I'll try to put a more condensed version of this in as an answer.

请先登录,再进行评论。

采纳的回答

Daniel
Daniel 2023-4-14
  1. It looks like you're using elementwise multiplication in the Gain blocks. If you're doing matrix math, you have to choose a matrix multiplication method for the gain blocks. You'll want to choose "Matrix (K*u)".
  2. I'm guessing that you haven't modified the initial condition for your integrator. You'll need to set that to a 2x1 vector as well (say, [0;0]).
  3. Finally, I think you should pass in your constant ref as a column vector rather than a row vector.
Once you've made the dimensionality and mathematics consistent, I think the system should run.
Some optimizations to bypass some of these headaches:
  1. You could remove the A and C Gain blocks (Gain and Gain2).
  2. You could disconnect y from Sum1, if D is 0 anyway, and then you could get rid of Sum1 and Gain1.
Then you would only be left with the mathematically nontrivial Gain blocks (Gain3 and Gain4).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by