Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 2 Differential Equation

3 3 Simulation

4 4 File > New > Model or

5 5 Drag Blocks from Sublibraries into Model File > Save as … example.slx

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

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

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

9 9 Renaming Blocks 1.Highlight name of block 2.Type new name (erasing old name) 3.Esc key (not Enter)

10 10 Change Parameters in a Block double-click the block

11 11 SublibraryBlockParameters SourcesStep Math OperationsSum (2) Math OperationsGain (2) ContinuousIntegrator (2) SinksScope SinksTo WorkspaceVariable name: y Saved as: Array Blocks for This Simulation

12 12 example.slx

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

14 14 Model Configuration Parameters PaneParameters SolverStart time: 0.0 Stop time: 20 Max step size: 0.1 Data Import/ExportTime: t Format: Array Output: y

15 15 Run then double-click Scope

16 16 Click Autoscale

17 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 on end axis([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

18 18

19 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

20 20 Create Subsystem Edit > Select All Diagram > Subsystem & Model Reference > Create Subsystem from Selection

21 21 Create Testbed for Testing Subsystem Rename 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: Array Save as … test.slx

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

23 23 Model Configuration Parameters PaneParameters SolverStart time: 0.0 Stop time: 20 Max step size: 0.1 Data Import/ExportTime: t Format: Array Output: y

24 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 on end axis([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

25 25 Exercise Simulate the following differential equation using a step input.


Download ppt "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."

Similar presentations


Ads by Google