+ All Categories
Home > Documents > Simulink

Simulink

Date post: 02-Jan-2016
Category:
Upload: rowan-mcmillan
View: 32 times
Download: 0 times
Share this document with a friend
Description:
Simulink. Create a model in Simulink Run simulation from Simulink Invoke simulation from a MATLAB script Create a subsystem Create a testbed for testing subsystem. Differential Equation. Find unit-step response in two cases:. Simulation. File > New > Model or. - PowerPoint PPT Presentation
25
1 Simuli nk Create a model in Simulink Run simulation from Simulink Invoke simulation from a MATLAB script Create a subsystem Create a testbed for testing subsystem
Transcript
Page 1: Simulink

1

Simulink

Create a model in Simulink

Run simulation from Simulink

Invoke simulation from a MATLAB script

Create a subsystem

Create a testbed for testing subsystem

Page 2: Simulink

2

𝑎 𝑑2 𝑦𝑑𝑥2

+√2𝑎 𝑑𝑦𝑑𝑥

+𝑦=𝑥

Find unit-step response in two cases:

Differential Equation

Page 3: Simulink

3

∫(∙)𝑑𝑥 ∫(∙)𝑑𝑥1/𝑎

√2𝑎

ΣΣ

𝑑2 𝑦𝑑𝑥2

= 1𝑎 [𝑥− 𝑦−√2𝑎 𝑑𝑦

𝑑𝑥 ]

+¿ +¿− −

𝑥 𝑦

𝑑𝑦𝑑𝑥

𝑑2 𝑦𝑑𝑥2

Simulation

Page 4: Simulink

4

File > New > Model or

Page 5: Simulink

5

Drag Blocks from Sublibraries into ModelFile > Save as … example.slx

Page 6: Simulink

6

Flipping a Block: Right-Click the Block, Select “Rotate & Flip”

Page 7: Simulink

7

Connect Two Blocks: Click Output, Drag Arrow to Input (Click 1st Block, Control-Click 2nd Block)

Page 8: Simulink

8

Tap into One Line, Creating a BranchPosition cursor on the line, control-click and drag new arrow

Page 9: Simulink

9

Renaming Blocks1. Highlight name of block2. Type new name (erasing old name)3. Esc key (not Enter)

Page 10: Simulink

10

Change Parameters in a Blockdouble-click the block

Page 11: Simulink

11

Sublibrary Block Parameters

Sources Step Step time: Initial value: Final value:

Math Operations Sum (2) List of signs:

Math Operations Gain (2) Gain: (1st Gain)Gain: (2nd Gain)

Continuous Integrator (2)

Sinks Scope

Sinks To Workspace Variable name: ySaved as: Array

Blocks for This Simulation

Page 12: Simulink

12

example.slx

Page 13: Simulink

13

Simulation > Model Configuration Parameters(from the example.slx window)

Page 14: Simulink

14

Model Configuration Parameters

Pane Parameters

Solver Start time: 0.0 Stop time: 20Max step size: 0.1

Data Import/Export Time: t Format: ArrayOutput: y

Page 15: Simulink

15

Run then double-click Scope

Page 16: Simulink

16

Click Autoscale

Page 17: Simulink

a = [1 10];curv = {'-b','--r'};figure(1)for n = 1:2 C = 1/a(n); K = sqrt(2*a(n)); set_param('example/C','Gain',num2str(C)) set_param('example/K','Gain',num2str(K)) sim('example') plot(t,y,curv{n}) hold onendaxis([0 20 0 1.2])set(gca,'YTick',0:0.2:1.2)set(gca,'FontSize',20)xlabel(‘t')ylabel('y')title('Step Response')legend('a = 1','a = 10','Location','SouthEast')set(findobj(gcf,'LineWidth',0.5),'LineWidth',2)saveas(1,'Step Response','png') 17

Create MATLAB script runexample.m and run it from MATLAB

Page 18: Simulink

18

Page 19: Simulink

19

Prepare New Model with Generic Input/Output

Remove these blocks: Step, Scope, To Workspace.Add In1 (Sources Sublibrary) and Out1 (Sinks Sublibrary).Rename In1 and Out1.File > Save as … diffEq.slx

Page 20: Simulink

20

Create Subsystem

Edit > Select AllDiagram > Subsystem & Model Reference > Create Subsystem from Selection

Page 21: Simulink

21

Create Testbed for Testing SubsystemRename subsystem block.Add Step on input. Step time: 0, Start value: 0, Final value: 1 Add Scope to output.Add To Workspace. Variable name: y, Save format: ArraySave as … test.slx

Page 22: Simulink

22

Simulation > Model Configuration Parameters(from the test.slx window)

Page 23: Simulink

23

Model Configuration Parameters

Pane Parameters

Solver Start time: 0.0 Stop time: 20Max step size: 0.1

Data Import/Export Time: t Format: ArrayOutput: y

Page 24: Simulink

a = [1 10];curv = {'-b','--r'};figure(1)for n = 1:2 C = 1/a(n); K = sqrt(2*a(n)); set_param(‘test/diffEq/C','Gain',num2str(C)) set_param(‘test/diffEq/K','Gain',num2str(K)) sim(‘test') plot(t,y,curv{n}) hold onendaxis([0 20 0 1.2])set(gca,'YTick',0:0.2:1.2)set(gca,'FontSize',20)xlabel(‘t')ylabel('y')title('Step Response')legend('a = 1','a = 10','Location','SouthEast')set(findobj(gcf,'LineWidth',0.5),'LineWidth',2)saveas(1,'Step Response','png')

24

Create MATLAB Script runtest.m and run it from MATLAB

Page 25: Simulink

25

𝑑𝑦𝑑𝑥

+2 𝑦=4 𝑥

Exercise

Simulate the following differential equation using a step input.


Recommended