Simulink error: Time-Varying State Space block
Afficher commentaires plus anciens
I have a Simulink error I can't figure out, relating to the Time-Varying State Space block dimensions.
I'm using this block so that i can also get x : normal SS block doesn't output x.
This is a simple 2x2 system, and the system dimensions are correct, but I'm getting a port dims error -- it seems to be Output Port 2 (the length-2 "x" output). It could be any system, i happen to have a closed-loop state space, but anything triggers the same error.
Any thoughts why?
I've spent way too much time trying to figure out what's going on...
SL model attached, and Runnable code below.

Error:
Matrix multiply dimensions propagation error. Error occurred while setting output port of 'LQR_post/Varying State Space/Product1' to have the dimensions [1 x 2]. A possible cause for this error is that these dimensions do not agree with the partial dimensions information present on other ports
Component:Simulink | Category:Model error
Error in port widths or dimensions. 'Input Port 2' of 'LQR_post/Varying State Space/Sum' is a [1x2] matrix.
Component:Simulink | Category:Model error
Code:
J = 1e-5;
b = 0.0016;
k = 0.632;
A = [0, 1; -k / J, -b / J];
B = [0; 1 / J];
C = [1 0];
D = [0];
sys = ss(A, B, C, D, ...
'StateName', {'x', 'x dot'}, ...
'InputName', {'r(ref)'}, ...
'OutputName', {'theta'});
Q = [1000 0 ; 0 0.001];
R = [ 0.01 ];
[K_lqr, S1, P1] = lqr(sys, Q, R);
sys_lqr = ss(sys.A - sys.B * K_lqr, sys.B * K_lqr * [1;0], sys.C, sys.D);
sys_lqr.StateName = {'theta', 'angVel'};
sys_lqr.InputName = {'r(ref)'};
sys_lqr.OutputName = {'theta'};
sys_lqr
Réponse acceptée
Plus de réponses (1)
Paul
le 18 Mar 2023
1 vote
Hi John,
In the Constant blocks for sys_lqr.B and sys_lqr.C try clearing the block parameter "Interpret vector parameters as 1-D — Treat vectors as 1-D"
5 commentaires
Paul
le 18 Mar 2023
For the model shown in the picture with constants feeding the Variable State Space block (with its default block parameters) that is feeding a scope, clearing those check boxes on the Constant blocks for B and C cleared up all errors for me.
Having said that, I think @Sam Chak's solution of redefining the C matrix to include the states in the output is nice approach.
Paul
le 21 Mar 2023
The error messages talk about a [1x2] matrix. For what Simulink calls 1D signals Simulink tries to infer dimensions. For example, those 1D signals indicated with a "2" on the signal line could be interpreted as either 1x2 or 2x1 and Simulink tries to figure that out. I thought it likely there was an issue with Simulink not being able to figure out which. By unchecking that box you take away that flexibility and it makes it easier for Simulink to figure out what's what. One tradeoff is matrix signals get logged as 3D, as discussed in your other question.
John
le 22 Mar 2023
Catégories
En savoir plus sur Signal Attributes and Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


