5892 MATLAB S-Function - 5892 Training MATLABSFunctionfor...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
5892 Training MATLAB S Function for Dynamic System Simulation 8 Jun 16 1 by Dr. Chao-Chung Peng
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
5892 Training Simulink S Function Where can we get the m file of S funtion? C:\Program Files\MATLAB\R2009b\toolbox\simulink\blocks Firstly, please copy the sfuntmpl.m file to your folder!! sfuntmpl.m function [sys,x0,str,ts,simStateCompliance] = sfuntmpl(t,x,u,flag) %SFUNTMPL General M file S function template % With M file S functions, you can define you own ordinary differential % equations (ODEs), discrete system equations, and/or just about % any type of algorithm to be used within a Simulink block diagram. % % The general form of an M FileS function syntax is: % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) % % What is returned by SFUNC at a given point in time, T, depends on the % value of the FLAG, the current state vector, X, and the current % input vector, U. 2 by Dr. Chao Chung Peng
Image of page 2
5892 Training Simulink S Function There are 6 main functions included in the S function To simulate complex system dynamic equation, only the above three functions are required. function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes function sys=mdlDerivatives(t,x,u) function sys=mdlUpdate(t,x,u) function sys=mdlOutputs(t,x,u) function sys=mdlGetTimeOfNextVarHit(t,x,u) function sys=mdlTerminate(t,x,u) 3 by Dr. Chao Chung Peng
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
5892 Training Simulink S Function function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes %============================================================================= % mdlInitializeSizes % Return the sizes, initial conditions, and sample times for the S function. %============================================================================= function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes % call simsizes for a sizes structure, fill it in and convert it to a % sizes array. % Note that in this example, the values are hard coded. This is not a % recommended practice as thecharacteristics of the block are typically % defined by the S function parameters. sizes = simsizes; sizes.NumContStates = 0; sizes.NumDiscStates = 0; sizes.NumOutputs = 0; sizes.NumInputs = 0; sizes.DirFeedthrough = 1; sizes.NumSampleTimes = 1; % at least one sample time is needed sys = simsizes(sizes); % initialize the initial conditions x0 = []; 4 by Dr. Chao Chung Peng
Image of page 4
5892 Training Simulink S Function The dynamic equations are going to be built in this function. Your control algorithm, analysis method & other processes are put in this function as well. Of course, one can just consider open loop systems and build another S function dedicated for control algorithm. %============================================================================= % mdlDerivatives % Return the derivatives for the continuous states. %============================================================================= function sys=mdlDerivatives(t,x,u) sys = []; % end mdlUpdate function sys=mdlDerivatives(t,x,u) 5 by Dr. Chao Chung Peng
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
5892 Training Simulink S Function This function is used to return system state response, output response and other interesting information.
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern