SIMULINK Linear and non-linear Systems Dipl.-Ing. U. Wohlfarth
SIMULINK Library Continuous Elements for modelling continuous-time systems Delays 1 s Integrator x = Ax+Bu y = Cx+Du (s 1) s(s+1) Zero Pole Transport Delay du/dt State Space 1 Memory Derivative s+1 Transfer Fcn Variable Transport Delay Dipl.-Ing. U. Wohlfarth 1
From ODE to Continuous Block Example: spring pendulum ODE: m ẍ(t) + k x(t) = 0 Solution in time domain: x(t) = x 0 cos (ω 0 t) + v 0 ω 0 sin (ω 0 t) L 0 k Transform to frequency domain: Transform function X(s) = 1 s 2 + ω 2 0 x m in SIMULINK: 0 Constant 1 s 2+2 Transfer Fcn (with initial outputs) Scope1 Dipl.-Ing. U. Wohlfarth 2
Examples for Continuous Resetting of Simulink Integrator Block: 0.5 Constant 1 s x o Integrator 2 >= Relational Operator Scope Anfangswert Constant1 Dipl.-Ing. U. Wohlfarth 3
Linearisation Linearisation of simulation models at arbitrary operating point Command: [A,B,C,D] = linmod( sys,x,u,para,xpert,upert) [Ad,Bd,Cd,Dd] = dlinmod( sys,t s,x,u) Further Matlab Commands from Control System Toolbox for analysing (ss, tf, zpk, bode, lsim) Dipl.-Ing. U. Wohlfarth 4
Find a point of equilibrium A trim point (point of equilibrium) corresponds to the steady state of a dynamic system ẋ = 0 Command: [x,u,y] = trim( sys, x0, u0, y0) further options help trim Dipl.-Ing. U. Wohlfarth 5
SIMULINK Library Nonlinear Elements for modelling of physical non-linearities Switches Manual Switch Rate Limiter Quantizer Dead Zone Saturation Backlash Relay Coulomb & Viscous Friction Switch Multiport Switch Dipl.-Ing. U. Wohlfarth 6
Example for Nonlinear Example for Quantizer Clock f(u) (u(1) 5)^2 + 3 Quantizer Parabel quantisierte Parabel ausgabe To Workspace Example for Backlash Signal Generator 1 Constant u y Rate LimiterBacklash ausgabe To Workspace Dipl.-Ing. U. Wohlfarth 7
SIMULINK Library Functions & Tables Tables Programmable functions Look Up Table Look Up Table (2 D) f(u) Fcn MATLAB Function MATLAB Fcn system S Function etc. Dipl.-Ing. U. Wohlfarth 8
Examples for Function & Tables Examples for Look Up Table auslese Ramp Look Up Table To Workspace Dipl.-Ing. U. Wohlfarth 9
Algebraic loops direct f eedthrough: Output port of a block drives input port of the same block, i.e. input depends on output at the same time u Sum y Blocks with direct f eedthrough: Sum, Gain, Product (State Space, Integrator, Transfer Function, Zero Pole) Solution with Algebraic Constraint: f(z) Solve f(z) = 0 Algebraic Constraint z Dipl.-Ing. U. Wohlfarth 10
Example for algebraic loops f(z) = 1 7 z3 1 28 sin z z 5 = 0 (1/7)* u^3 Fcn (1/28)* sin(u) Fcn1 f(z) Solve f(z) = 0 z z 3.9708653342418 5 Algebraic Constraint Display Constant z Sum Dipl.-Ing. U. Wohlfarth 11
S Functions Self-programmable functions Use S Function Block in SIMULINK Model programmable in Matlab (M Files) C, C ++, Fortran, Ada (MEX Files) Integration of earlier written programmes Dipl.-Ing. U. Wohlfarth 12
Example for S Functions P T 1 : Transfer function: Y (s) = 1 1 + st U(s) or state space: ẋ = 1 T x + 1 T u y = x Step pt1sfun S Function y To Workspace Dipl.-Ing. U. Wohlfarth 13
Example for S Functions function [sys,x0,str,ts] = pt1sfun(t,x,u,flag,t) A = [-1/T]; % State matrix % Unexpected flags % B = [ 1/T]; % Input matrix otherwise % error handling C = [ 1 ]; % Output matrix error([ Unhandled flag =,num2str(flag)]); D = [ 0 ]; % Feedthrough matrix=0 end switch flag, % end pt1sfun % Initialization % case 0, %===================== [sys,x0,str,ts]=mdlinitializesizes(a,b,c,d); % mdlinitializesizes %===================== % Derivatives % % case 1, function [sys,x0,str,ts]=... sys=mdlderivatives(t,x,u,a,b,c,d); mdlinitializesizes(a,b,c,d) % Outputs % sizes = simsizes; case 3, sys=mdloutputs(t,x,u,a,b,c,d); sizes.numcontstates = size(a,1); sizes.numdiscstates = 0; % not used flags sizes.numoutputs = size(c,1); case {2, 4, 9}, sys=[]; sizes.numinputs = size(b,1); Dipl.-Ing. U. Wohlfarth 14
Example for S Functions sizes.dirfeedthrough = 0; sizes.numsampletimes = 1; sys = simsizes(sizes); %==================== % mdloutputs %==================== x0 = zeros(size(a,1),1); % function sys=mdloutputs(t,x,u,a,b,c,d) str = []; sys = C*x + D*u; ts = [0 0]; % end mdlinitializesizes % end mdloutputs %=================== % mdlderivatives %=================== % function sys=mdlderivatives(t,x,u,a,b,c,d) sys = A*x + B*u; % end mdlderivatives Dipl.-Ing. U. Wohlfarth 15