Application Software Course Control & Simulink: By: Mahdi Akbari 09, November
Application Software Course Control & Simulink: By: Mahdi Akbari 09, November
Roots
G ( s) s 5 2s 4 3s 3 4s 2 5s 6
>> roots([1,2,3,4,5,6]) ans = 0.5517+ 1.2533i 0.5517- 1.2533i -1.4918 -0.8058+ 1.2229i -0.8058- 1.2229i
2
Symbolic Mathematic
Sym: Create symbolic object >> x=sym(x) Syms: Shortcut for creating multiple symbolic objects >> syms x,y
Symbolic Mathematic
Example
>> syms s >> f = (5*s^2 + 3*s +6)/(s^4 + 3*s^3 + 7*s^2 + 9*s +12); >> ilaplace(f )
Transfer Functions
s5 G( s) 4 3 2 s 2s 3s 4s 5
>> num=[1,5]; >> den=[1,2,3,4,5]; >> G=tf(num,den)
Transfer Functions
>> G=ss(A,B,C,D)
Example
>> A=[2.25, -5, -1.25, -0.5; 2.25, -4.25, -1.25, -0.25; 0.25, -0.5, -1.25,-1; 1.25, 1.75, -0.25, -0.75]; >> B=[4, 6; 2, 4; 2, 2; 0, 2]; >> C=[0, 0, 0, 1; 0, 2, 0, 2]; >> D=zeros(2,2); >> G=ss(A,B,C,D)
. x Ax Bu y Cx Du
10
Zero-pole-gain Description
>> KGain=6; >> Z=[-1.9294; -0.0353+0.9287j; -0.0353-0.9287j]; >> P=[-0.9567+1.2272j; -0.9567-1.2272j; 0.0433+0.6412j; +0.04330.6412j]; >> G=zpk(Z,P,KGain)
11
step responses
>> step (num,den) >> step (A,B,C,D) for find:
MP Rise time Fall time Over shoot
12
Form 3:
>> [y,x,t] = step (num,den,t) >> plot(t,y)
13
impulse responses
C (s) 1 R( s) s 1
Step ( s G(s) )
14
impulse responses
>> impulse (num, den)
15
Ramp responses
Step ( G(s)/S )
16
Feedback
>> Gt=feedback(G,H) >> syms g1 g2 % declare symbolic variables >> Gt=feedback(g1,g2,1); %Defult: negative feedback >> pretty(Gt)
17
Example:
18
19
[r, k] = rlocus (num, den) [r, k] = rlocus (num, den, k) [r, k] = rlocus (A, B, C, D) [r, k] = rlocus (A, B, C, D, K)
20
Example
>> num = [0 0 0 1]; >> den = [1 5 9 0]; >> rlocus(num, den);
21
Bode Diagrams
bode(num, den) bode(num, den, W) bode(A, B, C, D) (3.36) bode(A, B, C, D, W) [mag, phase, w] = bode (num, den) [mag, phase, w] = bode (num, den, w) [mag, phase, w] = bode (A, B, C, D) [mag, phase, w] = bode (A, B, C,D, w) [mag, phase, w] = bode (A, B, C, D, iu, w)
22
Example
>> %Bode diagram >> num= [29.125 33.2025 9.4627]; >> den= [0 1 0]; >> bode (num, den)
23
Nyquist Plots
nyquist (num, den, w) nyquist (A, B, C, D) nyquist (A, B, C, D, w) nyquist (A, B, C, D, iu, w) [re, im, w] = nyquist (num, den) [re, im, w] = nyquist (num, den, w) [re, im, w] = nyquist (A, B, C, D) [re, im, w] = nyquist (A, B, C, D, w) [re, im, w] = nyquist (A, B, C, D, iu, w)
24
Example
>> z = [ 1 3 + 7*i 3 7*i]; >> p = [ 1 3 5 3 + 7*i 3 7*i]; >> k = 30; >> nyquist (num, den)
25
What Is Simulink?
Simulink is a software package for modeling, simulating, and analyzing dynamical systems. It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two.
26
27
create a model
To create the model, first type simulink in the MATLAB command window. On Microsoft Windows, the Simulink Library Browser appears.
28
Model Editor
30
Go To Parent=Opens, if necessary, the parent of the current subsystem and brings its window to the top of the desktop.
31
32
33
first expand the Library Browser tree to display the blocks in the Sources library. Do this by clicking first on the Simulink node to display the Sources node Sources node to display the Sources library blocks. Finally right click on the Sine Wave node to select the Sine Wave
34
Copy the rest of the blocks in a similar manner from their respective libraries into the model window
35
With all the blocks copied into the model window, the model should look something like this.
Now its time to connect the blocks. Hold down the mouse button and move the cursor to the top input port of the Mux block. Notice that the line is dashed while the mouse button is down and that the cursor shape changes to double-lined cross hairs as it approaches the Mux block.
36
Press and hold down the Ctrl key. Press the mouse button, then drag the pointer to the Integrator blocks input port or over the Integrator block itself.
37
Finish making block connections. When youre done, your model should look something like this.
38
39
Now, open the Scope block to view the simulation output. Keeping the Scope window open, set up Simulink to run the simulation for 10 seconds. the simulation parameters by choosing Parameters from the Simulation menu. On the dialog box that appears notice that the Stop time is set to 10.0 (its default value)
40
Choose Start from the Simulation menu and watch the traces of the Scope blocks input.
41
42
43
colors
Simulink allows you to specify the foreground and background colors of any block select Screen color from the Simulink Format menu
44
Connecting Blocks
Connecting Two Blocks To auto connect two blocks: Select the source block. Hold down Ctrl and left-click the destination block.Simulink connects the source block to the destination block
When connecting two blocks, Simulink draws as many connections as possible between the two blocks as illustrated in the following example.
45
46
47
Drag the block over the line in which you want to insert the block.
Release the mouse button to drop the block on the line. Simulink inserts the block where you dropped it.
49
Disconnecting Blocks
To disconnect a block from its connecting lines, hold down the Shift key, then drag the block to a new location.
50
Creating Subsystems
As your model increases in size and complexity, you can simplify it by grouping blocks into subsystems. Using subsystems has these advantages: It helps reduce the number of blocks displayed in your model window. It allows you to keep functionally related blocks together
51
52
If you open the Subsystem block, Simulink displays the underlying system, as shown below.
53