Dimensions of arrays being concatenated are not consistent error .

2 views (last 30 days)
Hello. I have to simulate a system of 2 differential equations using the State Space block. Problem is that one of the variables, a mass m, has to come after 0,2s from start of simulation. I've tried using a Step with "To Workspace" block but it outputs the variable as a timeseries and gives an error. So I switched it to an If case with a clock and the error is different now :D - namely:
Simulation (Elapsed: 0.506 sec) ===
Error:Invalid setting in 'LB3/State-Space' for parameter 'A'.
Caused by:
Error evaluating parameter 'A' in 'LB3/State-Space'
Dimensions of arrays being concatenated are not consistent..
Here's a photo to better understand what's going on.Also in the subsystem is just a PID controller with a saturation block - nothing special. And simulation is 1 second long.
Any help is much appreciated.
  9 Comments
Jon
Jon on 12 Jan 2022
Edited: Jon on 12 Jan 2022
Glad that seems to be working for you.
I assume that Matrix A1 and A2 are computed with the two different values of mass m, and similarly the two different matrices B1 and B2 are computed with the two different values of m.
It looks like the two different values of m are 0 and 0.2. Is it just coincidence that the value for the mass and the switch time are both 0.2?
I realized that I put down this answer as a comment to the original post. I'm going to copy it in as an answer, so in case anyone else has a similar issue they will see it as a possible answer.
Also, if this answered your question you can then accept it.
Stilian Iliev
Stilian Iliev on 12 Jan 2022
Yea, it's just coincidence that both the mass and switch time are 0,2.

Sign in to comment.

Accepted Answer

Jon
Jon on 12 Jan 2022
There is a problem with your approach, which is setting the initial condition for the second block (the one that the switch is connected to after 0.2). Since physically the system states can not change instantaneously, the system state of the second block should match that of the first when the switch occurs. Unfortunately although the two systems will be driven by the same input, their states will not be the same because they have different parameters (the mass is different). So the states of the two blocks will not match at the time the switch occurs. To overcome this you would need a way to set the initial condition for the second block at the time of the switch. Unfortunately the Simulink state space block does not have any external input for setting the initial condition. The initial condition is a parameter, which stays constant throughout the simulation. So I don't see how you will do this.
Another approach, instead of using a switch would be to use two enabled subsystems, each with a state space block inside of them. The outputs of the two would be input to a merge block. Unfortunately I think you will have the same problem with initial conditions. There are some possibilities of resetting states, and hold outputs, that might hold some possibilities, but I don't immediately see a solution even using these.
There is one easy solution though if you have the Contol System Toolbox. The Varying State Space Model, which is in the Control System Toolbox, https://www.mathworks.com/help/control/ref/varyingstatespace.html would work perfectly for your application. You just feed it the time varying A,B,C,D and could provide any necessary switches (or maybe even just steps on those signals)

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!