State space system gives incorrect plot

4 views (last 30 days)
I made a state space system which is displayed above. At first sight everything looks fine, but in reality that isn't the case. When I click on 'run' and I open the scope after the simulation is done, I get a weird result:
The blue graph which is shown in the image above should not have a maximum of such a high value. To put it in perspective: I am simulating a 3DOF mass-spring-damper model (of a car), the graph being wrong is 'x [m] 3'. With the value being over 4000, that would mean that the wheel of my car is moving more than 4000 meters, while the car is driving over a bump with a height of 0.12m.
The thing is, there is no fault in the matrices which are filled in in the state-space block. I have checked those like 6 times together with my teacher, who has a Master of Science title to his name. I suspect the problem to be within the settings of MATLAB/Simulink. My teacher told me it'd probably be a laptop-specific problem, as he stated I did not do anything wrong. Does anyone have an idea of what the problem might be?
If somebody in any case thinks there actually still is something wrong with the matrices, they are as following:
The matrices are defined by the following free-body schematic, I have used mb, kb etc instead of ms, ks etc and used mw, kw etc instead of mu, ku etc:
  4 Comments
Sam Chak
Sam Chak on 11 Dec 2023
The MATLAB code is shown in your image. You need to copy/paste the code to the grey field by clicking this icon .
Julian
Julian on 11 Dec 2023
Allright, I will do so @Sam Chak.
Important note: as I wrote the matrices within the InitFcn callback I have put the characters A, B, C and D respectively at the A, B, C and D spot in the state-space block within Simulink.
md = 80; %Massa bestuurder [kg]
kd = 15000; %Veerconstante stoel [N/m]
cd = 4000; %Dempingconstante stoel [Nm/s]
mb = 450; %Massa voertuigbody [kg]
kb = 60000; %Veerconstante veer [N/m]
cb = 2800; %Dempingconstante schokdemper [Nm/s]
mw = 16; %Massa velg [kg]
kw = 236000; %Veerconstante band [N/m]
cw = 380; %Dempingconstante band [Nm/s]
A = [0 1 0 0 0 0
-kd/md -cd/md kd/md cd/md 0 0
0 0 0 1 0 0
kd/mb cd/mb -(kb+kd)/mb -(cb+cd)/mb kb/mb cb/mb
0 0 0 0 0 1
0 0 kb/mw cb/mw -(kw+kb)/mw -(cw+cb)/mw];
B = [0 0
0 0
0 0
0 0
0 0
kw/mw cw/mw];
C = [1 0 0 0 0 0
0 1 0 0 0 0
-kd/md -cd/md kd/md cd/md 0 0
0 0 1 0 0 0
0 0 0 1 0 0
kd/mb cd/mb -(kb+kd)/mb -(cb+cd)/mb kb/mb cb/mb
0 0 0 0 1 0
0 0 0 0 0 1
0 0 kb/mw cb/mw -(kw+kb)/mw -(cw+cb)/mw];
D = [0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
kw/mw cw/mw];

Sign in to comment.

Accepted Answer

Sam Chak
Sam Chak on 11 Dec 2023
Thank you for sharing the code. I didn't simulate this in Simulink but in MATLAB using the lsim() command. I plotted the two input signals: the Triangular pulse signal and its time derivative. Their amplitudes are relatively small but not exactly zero. The MATLAB results appear to differ from the Simulink results. In fact, the time derivative signal contains discontinuities, and the ode45 solver may produce some inaccurate results. You can try setting 'auto' (Automatic solver selection) in the Model Configuration Pane to see if there are improvements.
Check the parameters and equations in the code to evaluate if the input signals and output signals are produced correctly. Additionally, consider showing this to your system dynamics teacher to confirm if these are the expected outcomes.
%% parameters
md = 80; % Massa bestuurder [kg]
kd = 15000; % Veerconstante stoel [N/m]
cd = 4000; % Dempingconstante stoel [Nm/s]
mb = 450; % Massa voertuigbody [kg]
kb = 60000; % Veerconstante veer [N/m]
cb = 2800; % Dempingconstante schokdemper [Nm/s]
mw = 16; % Massa velg [kg]
kw = 236000; % Veerconstante band [N/m]
cw = 380; % Dempingconstante band [Nm/s]
%% state-space matrices
A = [0 1 0 0 0 0
-kd/md -cd/md kd/md cd/md 0 0
0 0 0 1 0 0
kd/mb cd/mb -(kb+kd)/mb -(cb+cd)/mb kb/mb cb/mb
0 0 0 0 0 1
0 0 kb/mw cb/mw -(kw+kb)/mw -(cw+cb)/mw];
B = [0 0
0 0
0 0
0 0
0 0
kw/mw cw/mw];
C = [1 0 0 0 0 0
0 1 0 0 0 0
-kd/md -cd/md kd/md cd/md 0 0
0 0 1 0 0 0
0 0 0 1 0 0
kd/mb cd/mb -(kb+kd)/mb -(cb+cd)/mb kb/mb cb/mb
0 0 0 0 1 0
0 0 0 0 0 1
0 0 kb/mw cb/mw -(kw+kb)/mw -(cw+cb)/mw];
D = [0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
kw/mw cw/mw];
%% state-space system
sys = ss(A, B, C, D);
%% input signals u(t) and du/dt
tstep = 1e-3; % time step
t = [0:tstep:8]'; % simulation time span
u = 0.12*triangularPulse(t - 3); % u (Triangular Pulse)
du = 0.06*sign(t - 3).*(sign(abs(t - 3) - 1) - 1); % du/dt
U = [u du]; % concatenated input matrix
%% generate simulated time response data of sys to input U
[y,t,x] = lsim(sys, U, t); % Output y = C·x
%% plot input signals
figure(1)
plot(t, U), grid on
title('Input Signals')
xlabel('t / sec'), ylabel('Amplitude')
legend('u(t)', 'du/dt')
%% plot time responses of outputs
figure(2)
plot(t, y), grid on,
title('Time responses of Outputs')
xlabel('t / sec'), ylabel('Amplitude')
legend('show', 'location', 'SE')
  3 Comments
Julian
Julian on 16 Jan 2024
Thank you very much for your answer, @Sam Chak,
After downloading the needed add-ons and finetuning the code to my liking, it works properly and does give the expected results. So thanks a lot, for your help and effort.
Sorry for my very late response, it has been crazy busy right before christmas, and also now, right after holidays.
It seems like my Simulink generally has quite some issues with simulating state-space systems, as I'm experiencing problems again, trying to simulate another vehicle dynamics model.
Julian
Julian on 16 Jan 2024
Hi @Paul,
The scope is difficult to read indeed. Though, plotting al the graphs into the same scope should not be a problem at all, as I have done it before with non-state-space systems (but same vehicle dynamics model). It is also part of the assignment.
To add to that, the graph @Sam Chak shows represents the expected graphs from the state-space system in Simulink. As Sam indicates, there seems to be a problem with the derivative of the input (0.12) as the value is close to 0, which would give the very maximum value of the graph. So the plot generated by Simulink is very off anyway.

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!