www.pudn.com > kicILC-control.rar > nzz.m, change:2013-04-23,size:2275b

```function [sys,X0]=nzz(~,x,u,FLAG)

% DCMOTOR
%       S-function describing the non-linear dynamic equations of a
%       simple dcmotor given by eqs. 3.3-1, 3.3-5 and 3.3-6 of the
%       textbook "Electromechanical Motion Devices" P. Krause, McGraw
%       Hill 1989.
%
%	SYS=dcmotor(t,x,u,FLAG) returns, depending on FLAG, certain
%	system values given the current values of time, t, state
%       vector, x, and input vector, u.
%
%	FLAG is used to indicate the value to be returned in SYS.
%       For a continuous system the following flags are used:
%
%         FLAG=0 to initialize the system
%	  FLAG=1 to return state derivatives
%         FLAG=3 to return system outputs
%
% Calling DCMOTOR with a FLAG of zero: [SIZES]=DCMOTOR([],[],[],0),
%       returns a vector, SIZES, which contains the size of the state
%       vector and other parameters (see FLAG=0) as indicated below.
%         SIZES(1) number of states
%         SIZES(2) number of discrete states
%         SIZES(3) number of outputs
%         SIZES(4) number of inputs
%         SIZES(5) number of roots (currently unsupported)
%         SIZES(6) direct feedthrough flag
%         SIZES(7) number of sample times
%

% ------------------------------------------------------------------------ %

%% Here, you must declare all the parameters of the system as global
%  of course this means that they should be loaded in the MATLAB
%  workspace before running this S-function

% global Rf Ra Laa Lff Laf Bm Jm

if FLAG == 0,	% initialize system
% SYS and X0
% dcm_par;
% This system has 3 states (x,v,i), 1 input (e), and 3 output (x,v,i)
nx = 2; % # of states
ny = 2; % # of outputs
nu = 1; % # of inputs
sys = [nx; 0; ny; nu; 0; 0];
% Initial Conditions
X0 = [1 0]';
elseif FLAG == 1, % states derivatives
% Here write the State Equations.
k1=4000;
k2=620000;
E1=2500;
E2=5000;
Tref=348;
dx(1) = -k1*exp(-E1/u/Tref)*x(1)*x(1);
dx(2) = k1*exp(-E1/u/Tref)*x(1)*x(1)-k2*exp(-E2/u/Tref)*x(2);
%x(1)<=1;
sys = dx;
elseif FLAG == 3,  % system outputs
y(1) = x(1);
y(2) = x(2);
sys = y;
else
sys = [];
end
```