Plotting State Space Model with Disturbance
Afficher commentaires plus anciens
Hi! I am trying to simulate a very simple dynamical system with disturbance matrix u (Dirac function).
mx''+bx'+kx=u(t)
I want to drow the displacement(position) and velocity of the system. This is my code, which seems to be not completely correct:
m=5;
c=20;
k=100;
% solves m x''+ c x' + k x = f(t)
t=0:0.1:10
A=[0 1; -(-k/m) (-c/m)];
B=[0 ; (1/m)];
C=[1 0];
D=0;
u=ones(2,1)*(heaviside(t-2)-heaviside(t-2.5));
sys1=(ss(A,B,C,D);
step (sys1)
Any suggestion for completing the code?
Thanks Sam
Réponse acceptée
Plus de réponses (2)
Sam
le 6 Mai 2015
0 votes
4 commentaires
Sebastian Castro
le 6 Mai 2015
Ah, yes, didn't even notice that part! The step function will always input a step response. What you want to look into is the lsim function, where you can specify your own input vector.
- Sebastian
Sam
le 6 Mai 2015
Sebastian Castro
le 6 Mai 2015
Your system only has 1 input (B matrix has 1 column), while you defined "u" as having 2 rows (it's a 2x101 matrix). It worked for me with these changes:
u = heaviside(t-2)-heaviside(t-2.5);
lsim(sys1,u,t);
- Sebastian
Sam
le 6 Mai 2015
Marco Boutrus
le 31 Mar 2020
0 votes
Hello! a very old page! but i hope u guys are still active!
i have the same formula that i need to plot (both the x and the v graphs). however i cant seem to change the stepsize, if i add
dt = 0.25; % Time step [s]
t = 0:dt:10; % Time range [s]
do i have to rewrite the whole ss form or is there a better way?
Marco
Catégories
En savoir plus sur MATLAB 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!