Download presentation
Presentation is loading. Please wait.
Published byGavin Hunt Modified over 9 years ago
1
Intro to Simulink http://jagger.me.berkeley.edu/~pack/e177 Modified by Gary Balas 20 Feb 2011 Copyright 2005-8, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. http://jagger.me.berkeley.edu/~pack/e177http://creativecommons.org/licenses/by-sa/2.0/
2
What is Simulink? First perspective –Ordinary Differential Equation (ODE) solver –Differential equations described by block diagrams –Graphical interface to create/modify block diagrams There’s more, but we will probably not have time to cover –Hybrid systems –…–…
3
What is Simulink?
4
ODE theory Consider an input/output system, with m inputs, q outputs, and governed by a set of n, first-order, coupled differential equations Here, f 1 is a function that takes in 1+n+m arguments, and returns 1 value. Similar for f 2, … and h 1, h 2, …
5
ODE theory Look at the first n equations At each time t, the –current value of t –current value of x 1, x 2, … –current value of u 1, u 2,… dictate the current value of the rate-of-change of x i. So, an initial value of x, x(t 0 ) = x 0, and the value of u(t) for t≥t 0 yield the solution x(t) for t≥t 0. Unless the form of the functions f i is particularly simple, solving for x must be done numerically. These are called the state equations, and x is called the state.
6
Output Equations Look at the rest of the equations At each time t, the –current value of t –current value of x 1, x 2, … –current value of u 1, u 2,… dictates the current value of y i. So, these equations are quite simple, just how the outputs y (at time t) are defined as functions of the state (x) and input (u) at time t. Back to the state equations, where the action is…
7
Numerical Solution of ODEs Simulink solves the state equations using numerical integration techniques, such as 4 th and 5 th order Runge-Kutta formulae. You can learn more about numerical integration by taking Math 2373. We will not discuss this important topic in this class. However, to understand in a very crude manner how ODE solvers work, we will revisit the forward Euler method of approximate solution. Write the state equations in concise form
8
Numerical Solution of ODEs Taylor's expansion on a time-dependent function x, ignoring the higher order terms, gives an approximation formula Roughly, the ``smaller'' δ is, the better is the approximation. Euler's method propagates a solution by repeatedly using this approximation for a fixed δ,called the stepsize. Writing out the first 4 time steps (ie., t=0, δ, 2δ, 3δ, 4δ) gives and so on. An approximate solution can be quickly propagated by calling the subroutine for f once each timestep. Using the state equation
9
Numerical Solution of ODEs Once the approximate solution, x, is computed, computing the output, y simply involves evaluating the function h In Runge-Kutta methods, more sophisticated approximations are made, resulting in –more computations (e.g., 4 evaluations of f for every time step), –much greater solution accuracy. In effect, more terms of the Taylor series are used, involving matrices of partial derivatives, and even their derivatives, but without actually requiring explicit knowledge of these derivatives of the function f
10
“direct feedthrough” in Output Equations In general, the output equations are of the form If, in fact, h does not have explicit u dependence, then the system is said to “have no direct feedthrough from u to y” Note: no direct feedthrough does not mean that u doesn’t affect y. It is still true that u drives x in the state equations, and the values of x define the values of y.
11
ODE notation Recall, for shorthand, we write the state and output equations as State equations Output equations
12
General Form of a Continuous-Time block Input: u (vector valued) Output: y (vector valued) Internal State: x (vector valued) Governing relationship between these signals is of the form Each block “knows” –the functions f and h which define its behavior, and –at all times, the current value of its internal state x Initial value is specified by user. Implicitly, all blocks have time as an input.
13
Sources and Sinks Source: a block with no inputs, only outputs –Typical example: fixed “waveform” signal Sink: a block with no outputs, only inputs –Specific examples are blocks that represent data-logging (blocks that capture signals, but don’t “pass” anything on to another block)
14
Evolving a solution: Psuedo-code Current time: t Loop through blocks, determine output of each block –This uses the current time, and internal state x and output function h associated with the block. Using diagram, determine input to each block –The diagram dictates how the inputs to blocks are combinations of outputs of blocks. If the outputs are already known, then the inputs are determinable Using governing equations, determine for each block –This uses the current time, and internal state x and state function f associated with the block. Advance time, to t+δ –Use numerical integration formula (Euler, Backwards Euler, Runge- Kutta, etc) to advance one time-step Update internal state x for each block. Repeat.
15
Simulink Library The Simulink Library has folders of prebuilt blocks that have well-defined behaviors. We will primarily use 6 Libraries –Continuous –Math Operations –Signal Routing –Sinks –Sources –User-defined Functions
16
Continuous Library One commonly used block in continuous-time library is the Integrator. The appearance and equations of the block are Equivalently hence the name. The user specifies the value of x(0) by double-clicking on the icon, and entering value in dialog box.
17
Continuous Library - Integrator Double click
18
Running Simulink from Command line/function The sim command can be used to run a simulation from the command line, or inside a function, e.g., >> sim(‘ModelName’,TimeSpan,Options) The simset command sets options for the simulation. Two useful properties when sim is invoked in a function are SrcWorkspace: The workspace where dialog box entries are evaluated Default: ‘base’. Other options include ‘current’ and ‘parent’ DstWorkspace: The workspace where to assign variables defined in model Default is ‘current’. Other options are ‘base’ and ‘parent’ function [arg1,arg2] = analyzesim(ModelName)... Opt = simset(); % set options sim(ModelName,TSpan,Opt);...
19
Simple Examples Build two simple examples using –Step Function (from Source) –Integrator (from Continuous) –Scope (from Sink) The files are e177model1.mdl and e177model2.mdl Be sure to create a variable named mygain in the workspace before running model2 – recall this is what is entered in the dialog box of the Gain block. A more complicated example is from ME132. For illustrative purposes, the files are given. The setup and model files are –setupAW132.m –exampleAW132.m Run the setup file, then run the simulations. Be sure to try changing the Antiwindup gain, as well as the gain on the measurement noise.
20
Simple Example – Step/Int/Gain/Scope Build two simple examples using –Step Function (from Source) –Integrator (from Continuous) –Scope (from Sink)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.