0% found this document useful (0 votes)
9 views9 pages

Simulink Tutorial R2013a

The document provides instructions for using MATLAB and Simulink to model and solve simple differential equations. It explains how to open Simulink, add common blocks like Constant, Integrator and Out, and connect them to model equations. It also discusses running the model simulation, viewing results in the workspace and command window, and connecting Simulink with MATLAB for further analysis and exploration. Step-by-step guidance is given for setting up models of two sample differential equations.

Uploaded by

Oindri Kar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Simulink Tutorial R2013a

The document provides instructions for using MATLAB and Simulink to model and solve simple differential equations. It explains how to open Simulink, add common blocks like Constant, Integrator and Out, and connect them to model equations. It also discusses running the model simulation, viewing results in the workspace and command window, and connecting Simulink with MATLAB for further analysis and exploration. Step-by-step guidance is given for setting up models of two sample differential equations.

Uploaded by

Oindri Kar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

School

 of  Engineering  
Environmental  Engineering  Systems  (ENGG*2560)  
W2014  (MATLAB  R2013a;  [Link])  

Simulink®  Tutorial  :    Simple  Differential  Equations  


 

Open  Matlab  

Adjust  Folder  to  your  desired  location  

Open  a  Simulink  Model  

Opens  a  model  file  window  

A  good  idea  to  save  your  file  right  away    

(NoSpaces  in  names;  files  will  have  a  *.slx  extension;  


older  Simulink  files  have  a  *.mdl  extension)  

Simulink  Tutorial  (January  2014)       1  


Open  Simulink  Library  Browser  

Simulink  Library  Browser  provides  all  of  the  functionality.    Start  in  “commonly  used  blocks”  for  beginners  
and  for  the  most  common  
functions.  

Select  Commonly  Used  Blocks  

To  bring  a  function  into  your  model  …  Click,  Drag  &  


Drop    

Simulink  Tutorial  (January  2014)       2  


Initial  Equation  to  solve:  

𝑑𝑦
=   −0.4;            𝑦 0 = 100;      𝑦 5 =?  
𝑑𝑥

Drag  in  a  CONSTANT,  INTEGRATOR  and  OUT  block.      

Label  each  block  as  you  add  it  to  your  model  

INTEGRATOR  block  …  label  with  dy/dx    

Double  click  on  CONSTANT  block.    Opens  a  window  permitting  you  to  set  the  constant  to  -­‐0.4.  

Logic  of  Simulink’s  INTEGRATOR  Block  è  Feed  into  the  INTEGRATOR  block  what  dy/dx  is  equal  to.  

  In  this  case,  feed  in  the  CONSTANT  of  -­‐0.4.  

Connect  CONSTANT  block  to  INTEGRATOR  block  by  clicking  on  the  little  out  arrow  and  dragging  
to  the  little  in  arrow  on  the  INTEGRATOR  block.    (a  short  cut  for  these  connections  will  pop  up)  

The  successful  integration  of  dy/dx  is  y.    Thus,  connect  the  
out  from  the  INTEGRATOR  block  to  the  OUT  block  and  
label  as  “y  out”.  

Defining  the  initial  condition  for  the  differential  equation.    


Double  click  on  the  INTEGRATOR  block.      

You  have  the  option  of  keeping  the  initial  


condition  hidden  (internal)  or  use  the  external  
option  to  display  the  initial  condition  in  your  
model  screen.    

With  the  External  option,  the  INTEGRATOR  block  has  an  


additional  input.    Add  a  CONSTANT  block  with  your  initial  
condition  and  connect  to  the  INTEGRATOR  block.      

Simulink  Tutorial  (January  2014)       3  


The  resulting  model  should  look  like  
this.  

Run  Model  è  using  “PLAY”  button    

Results  in  Matlab  WORKSPACE.    Click  


on  “yout”  in  WORKSPACE  to  see  
specific  results  and  “tout”  provides  
the  corresponding  independent  
variable  values.      

Type  “plot  (tout,  yout)”  in  the  MATLAB  COMMAND  


WINDOW  to  see  plot  of  results.    

MATLAB  plot  features  offers  ability  to  control  plot.  

Simulink  Tutorial  (January  2014)       4  


Connecting  MATLAB  and  Simulink  for  greater  functionality.  

Double  click  the  CONSTANT  block  


and  change  the  -­‐0.4  to  a  variable  
(K1).      

In  Matlab’s  COMMAND  WINDOW,  


type    

K1  =  [  -­‐0.4    -­‐0.8]  

RePLAY,  RePLOT  

K1  is  now  a  vector  of  values  and  the  


Simulink  PLAY  runs  the  model  for  
each  value.    The  results  PLOT  
captures  both  values  of  K1.  

This  is  a  very  efficient  means  to  


explore  sensitivities  and  parameter  
uncertainties.  

Core  Aspects  of  RUNNING  MATLAB  /  Simulink:  

• Label  blocks  as  you  add  them  


• Feed  into  the  INTEGRATOR  block  what  the  derivative  is  equal  to  
• Output  of  the  INTEGRATOR  block  is  the  integral  of  the  derivative    (dy/dx  becomes  y)  
• Do  not  forget  initial  conditions  
• Use  MATLAB’s  plot  and  other  features  can  be  combined  for  powerful  advantages  

   

Simulink  Tutorial  (January  2014)       5  


Next  Equation…  

𝑑𝑦
=   −0.4𝑦 − 60;      𝑦 0 = 100;      𝑦 5 =?  
𝑑𝑥

Feed  into  the  INTEGRATOR  block  


needs  to  be  -­‐0.4y-­‐60  (or  K1*y  -­‐  
60).    

Bring  in  SUM  block  and  PRODUCT  


block.      

PRODUCT  block  handles  K1  *  y  


with  “y”  coming  from  the  output  
of  the  INTEGRATOR  block.  

IF  you  double  click  on  SUM  block  you  can  change  shape  of  the  block  and  you  can  add  additional  “+”  and  
“-­‐“  signs  to  handle  more  terms.    Similarly  for  PRODUCT  block  –  you  can  add  “*”  and  “/”  for  more  terms.      

To  change  the  time  duration  for  the  


simulation  you  change  the  entry  to  the  right  
of  the  PLAY  button.        

PLAY  model  and  PLOT.    You  can  see  the  two  values  of  K1  
are  still  active.    

   

Simulink  Tutorial  (January  2014)       6  


Second  Order  Differential  Equations  

𝑑!𝑦 𝑑𝑦 𝑑𝑦
+ 3   − 10  𝑦 + 15 = 0;                     =  10;      𝑦 0 = 5;            𝑦 1 =?  
𝑑𝑡 ! 𝑑𝑡 𝑑𝑡 !

Two  INTEGRATOR  blocks  are  required  to  handle  a  second  order  differential  equation.    

Principles  remain  the  same.    Need  to  feed  into  each  what  the  integral  is  equal  to.    It  is  good  to  rewrite  
equation  as  the  derivative  equals…  

𝑑!𝑦 𝑑𝑦
!
=   −3   + 10  𝑦 − 15    
𝑑𝑡 𝑑𝑡
!!!
The  output  from  the    
!! !
INTEGRATOR  block  is  dy/dt.    
The  output  is  available  for  the  -­‐
3  dy/dt  term.    The  output  from  
the  dy/dt  INTEGRATOR  block  is  
y  and  this  is  available  for  the  10  
y  term.      The  resulting  Simulink  
model  is  given  below.      Note:    
the  initial  conditions  have  been  
left  as  INTERNALLY  specified  
(hidden).  

The  model  has  used  the  GAIN  


block  as  an  alternate  for  
multiplying  two  terms.      

The  RESULT  is:    

The  BLUE  line  is  the  result  for  dy/dt  as  a  function  of  
time.    The  GREEN  line  is  the  value  for  y.      

   

Simulink  Tutorial  (January  2014)       7  


Coupled  ODE’s    

𝑑𝑦
+ 3  𝑧 = 0; 𝑦 0 =  8  
𝑑𝑡
𝑑𝑧
− 10  𝑦 = 0; 𝑧 0 =  5  
𝑑𝑡

The  feed  into  the  dy/dt  INTEGRATOR  


block  is  -­‐3z  as  it  should  be.    

Likewise  for  the  dz/dt  INTEGRATOR  


block.      

The  necessary  values  of  y  and  z  come  


from  the  output  of  the  two  
INTEGRATOR  blocks.  

Solution  (BLUE  is  y  &  GREEN  is  z):  

   

Simulink  Tutorial  (January  2014)       8  


Solutions  are  NUMERICAL  

  Simulink  solves  the  equations  numerically  not  analytically.    To  explore  and  control  the  numerical  
methods  used.    Go  to  SIMULATION  and  CONFIGURATION  PARAMETERS  from  the  menu  bar.      

  Simulink  offers  a  substantial  collection  of  numerical  method  options.    It  is  necessary  to  recognize  
that  the  solution  depends  on  the  method  chosen  and  the  parameters  chosen  within  that  method.    A  
method  and  parameter  set  may  not  be  suitable  for  a  given  system  and  thus  may  lead  to  completely  
erroneous  results.    (This  screen  is  your  NUMERICAL  METHODS  course!)  

Simulink  Tutorial  (January  2014)       9  

You might also like