Matlab/Simulink For System Dynamics and Control

Download Report

Transcript Matlab/Simulink For System Dynamics and Control

By Dr. Hong Zhang

 ◦ ◦ ◦ ◦ ◦ Octave http://www.gnu.org/software/octave/ Very Similar commands Can run most M-files No built-in Simulink package Pure command line

 ◦ ◦ ◦ ◦ Scilab http://www.scilab

.org/ Some commands are different Built-in Xcos to clone Simulink Some Graphic interface

Given a transfer function a b 2 2 den = [b s s num = [a 2 2 2 We can define it in Matlab as 2 + a 1 s + a 0 + b , a , b 1 1 , a , b 1 0 0 s + b ]; ]; sys = tf(num, den); 0

   Unit step response step(sys) Unit impulse response impulse(sys) Arbitrary input response t = t start : t interval lsim(sys, u, t) : t finish ; u = f(t); % u is a function of t, e.g. ramp is u=t;

  Just bring the output to a variable. E.g.

y1 = step(sys); y2 = impule(sys); y3 = lsim(sys, u, t); Then we can use the variable. E.g.

plot(t,y1, t, y2) plot(t, u, t, y3)

[r, p, k] = residue(num, den); Where

r: root p: pole k: constant

If there are complex terms, we can add the two conjugate ones together to get a 2 nd order real term.

Click the Simulink icon in Matlab window Matlab main window Simulink modeling window Simulink library browser

 Find, drag and drop following blocks to the window ◦ ◦ Simulink Sources   Continuous Step ◦ Sinks  Scope You will get  Transfer Function Output Input Building Blocks Except sources and sinks, every block should have an input and an output.

 Double click the Transfer function block. Change Numerator to [1], denominator to [1 3 2]

   Link the blocks by drag the output to input Double click Scope to show Scope window Click Ctrl+T or Simulation  Start or button

 Change the spring constant and damping ratio, then you can have different response. [1 2 1] [1 2 12] Hint: Hit the binocular to auto-scale the plot.

 Replace the source with a Sine wave with frequency =3 Hint: Double click the block name to change it.

 Hint: ◦ Hold Ctrl and click to tap an output line ◦ Right click a block and select Format to flip or rotate a block

Rewrite

m x

c

Ý

kx

f

(

t

)

as

Ý  1

m

[

f

(

t

) 

c

Ý

kx

]   Assume m=2kg c=3NSec/m k=3N/m f(t)=1(t)N