Plotting State Space Model with Disturbance

11 ビュー (過去 30 日間)
Sam
Sam 2015 年 5 月 6 日
回答済み: Marco Boutrus 2020 年 3 月 31 日
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

採用された回答

Sebastian Castro
Sebastian Castro 2015 年 5 月 6 日
I see...
In your A matrix, your spring term is -(-k/m) , and that double negative makes it positive and therefore an unstable system. Try removing one of those minus signs and you should be good.
Also, couple other things:
  1. You have an extra parenthesis when you define sys1
  2. If you want to output both position and velocity, then your C matrix should be [1 0;0 1] , or eye(2)
- Sebastian

その他の回答 (2 件)

Sam
Sam 2015 年 5 月 6 日
Dear Sebastian,
thank you for the answer. I corrected both of them, and it works now, but the excitation (U) seems not to be involved in the calculation.
U term can be a dirac impulse (as you see in my code), or a periodic function like sin. Actually I want to study the system response in underdamped, overdamped and critical situation.
  • b2<4mk - underdamping;
  • b2>4mk - overdamping;
  • b2=4mk - critical damping.
  4 件のコメント
Sebastian Castro
Sebastian Castro 2015 年 5 月 6 日
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
Sam 2015 年 5 月 6 日
solved. Thanks again.

サインインしてコメントする。


Marco Boutrus
Marco Boutrus 2020 年 3 月 31 日
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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by