State space system gives incorrect plot

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 Commenti

If you would like us to check, please copy and paste the code that describes the state-space matrices above. Additionally, provide the input signal, preferably in a mathematical equation. Has your teacher ever suspected that the spike was caused by the Derivative block (du/dt)?
Furthermore, has your teacher verified whether the time-derivative of the input signal is correctly modeled? Providing the input signal allows us to gain insights for evaluating and determining the accuracy of the model.
Julian
Julian il 11 Dic 2023
Modificato: Sam Chak il 11 Dic 2023
Then I would have to write a code in MATLAB which gives the matrices, I have them written on paper right now, I didn't think it would be much appreciated when I share those.
The placing of the derivative is mathematically correct, the only thing which could be wrong regarding the derivative, is what the mux does with the input signals.
The input signal is a small dataset ranging from [0-5] (time) and peeks at 0.12 (output of the signal block):
The weird thing is, the red line within the scope, providing the input of the system, stays at 0 all the time (regarding the scope). Filling in 0 in a derivative would obviously give a maximum of the graph, so that makes sense. But it does not make sense that the input stays at 0 in the first place. That honestly is my biggest question mark out of this: why does the graph show that the input stays at 0?
The MATLAB code is shown in your image. You need to copy/paste the code to the grey field by clicking this icon .
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];

Accedi per commentare.

 Risposta accettata

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 Commenti

" why does the graph show that the input stays at 0?"
I find the scope graph very difficult to read. It contains 10 signals, at least one of which has a very different range than the others. Why not make one scope per signal of interest, each properly scaled, and show those. If I'm following correctly, the signals of interest, at least initially, would be the two signals going into the mux.
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.
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su General Applications in Centro assistenza e File Exchange

Prodotti

Release

R2023a

Richiesto:

il 10 Dic 2023

Commentato:

il 16 Gen 2024

Community Treasure Hunt

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

Start Hunting!

Translated by