State space system gives incorrect plot
4 views (last 30 days)
Show older comments

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
Accepted Answer
Sam Chak
on 11 Dec 2023
Hi @Julian
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
More Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


