⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tesfunc.m

📁 Tennessee eastman 的Matalb仿真程序
💻 M
📖 第 1 页 / 共 5 页
字号:
function [sys,x0,str,ts] = tesfunc(t,x,u,flag)
%                Tennessee Eastman Process Control Test Problem
% 						        Re-Written in MATLAB 5.2 
%								         	by	
%     					Martin Braun and Daniel E. Rivera
%
%										  Box 876006
%						Control Systems Engineering Laboratory
%								Manufacturing Institute
%				Department of Chemical, Bio and Materials Engineering
%								Arizona State University
%								  Tempe, AZ 85287-6006
%									  Copyright 1999
%
% 						  	Please report any problems to:
% 								  mwbraun@imap4.asu.edu
%								  daniel.rivera@asu.edu
%
%  Please note, due to the way MATLAB executes the exp() function,
%  there are slight discrepancies in the output compared to the FORTRAN
%  version.
%
% ************************************************************************
%                Tennessee Eastman Process Control Test Problem
% 
%                     James J. Downs and Ernest F. Vogel
% 
%                   Process and Control Systems Engineering
%                        Tennessee Eastman Company
%                               P.O. Box 511
%                           Kingsport,TN  37662
% 
% ************************************************************************
%   Reference:
%     "A Plant-Wide Industrial Process Control Problem"
%     Presented at the AIChE 1990 Annual Meeting
%     Industrial Challenge Problems in Process Control,Paper #24a
%     Chicago,Illinois,November 14,1990
% 
%  Revised 4-4-91 to correct error in documentation of manipulated variables
%
%
% t -> time vector
% x -> state vector
% u -> input vector
% flag -> S-Function Flag
%
% See below for output description.
% 
%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-File S-function syntax is:
%       [SYS,X0,STR,TS] = 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.
%
%   FLAG   RESULT             DESCRIPTION
%   -----  ------             --------------------------------------------
%   0      [SIZES,X0,STR,TS]  Initialization, return system sizes in SYS,
%                             initial state in X0, state ordering strings
%                             in STR, and sample times in TS.
%   1      DX                 Return continuous state derivatives in SYS.
%   2      DS                 Update discrete states SYS = X(n+1)
%   3      Y                  Return outputs in SYS.
%   4      TNEXT              Return next time hit for variable step sample
%                             time in SYS.
%   5                         Reserved for future (root finding).
%   9      []                 Termination, perform any cleanup SYS=[].
%
%
%   The state vectors, X and X0 consists of continuous states followed
%   by discrete states.
%
%   Optional parameters, P1,...,Pn can be provided to the S-function and
%   used during any FLAG operation.
%
%   When SFUNC is called with FLAG = 0, the following information
%   should be returned:
%
%      SYS(1) = Number of continuous states.
%      SYS(2) = Number of discrete states.
%      SYS(3) = Number of outputs.
%      SYS(4) = Number of inputs.
%               Any of the first four elements in SYS can be specified
%               as -1 indicating that they are dynamically sized. The
%               actual length for all other flags will be equal to the
%               length of the input, U.
%      SYS(5) = Reserved for root finding. Must be zero.
%      SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function
%               has direct feedthrough if U is used during the FLAG=3
%               call. Setting this to 0 is akin to making a promise that
%               U will not be used during FLAG=3. If you break the promise
%               then unpredictable results will occur.
%      SYS(7) = Number of sample times. This is the number of rows in TS.
%
%
%      X0     = Initial state conditions or [] if no states.
%
%      STR    = State ordering strings which is generally specified as [].
%
%      TS     = An m-by-2 matrix containing the sample time
%               (period, offset) information. Where m = number of sample
%               times. The ordering of the sample times must be:
%
%               TS = [0      0,      : Continuous sample time.
%                     0      1,      : Continuous, but fixed in minor step
%                                      sample time.
%                     PERIOD OFFSET, : Discrete sample time where
%                                      PERIOD > 0 & OFFSET < PERIOD.
%                     -2     0];     : Variable step discrete sample time
%                                      where FLAG=4 is used to get time of
%                                      next hit.
%
%               There can be more than one sample time providing
%               they are ordered such that they are monotonically
%               increasing. Only the needed sample times should be
%               specified in TS. When specifying than one
%               sample time, you must check for sample hits explicitly by
%               seeing if
%                  abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD)
%               is within a specified tolerance, generally 1e-8. This
%               tolerance is dependent upon your model's sampling times
%               and simulation time.
%
%               You can also specify that the sample time of the S-function
%               is inherited from the driving block. For functions which
%               change during minor steps, this is done by
%               specifying SYS(7) = 1 and TS = [-1 0]. For functions which
%               are held during minor steps, this is done by specifying
%               SYS(7) = 1 and TS = [-1 -1].

%   Copyright (c) 1990-1998 by The MathWorks, Inc. All Rights Reserved.
%   $Revision: 1.12 $

%
% The following outlines the general structure of an S-function.
%
switch flag,

  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0,
    [sys,x0,str,ts]=mdlInitializeSizes(t);

  %%%%%%%%%%%%%%%
  % Derivatives %
  %%%%%%%%%%%%%%%
  case 1,
    sys=mdlDerivatives(t,x,u);

  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
    sys = mdlOutputs(t,x,u);

  %%%%%%%%%%%%%%%%%%%
  % Unhandled flags %
  %%%%%%%%%%%%%%%%%%%
  case { 2, 4, 9 },
    sys = [];

  %%%%%%%%%%%%%%%%%%%%
  % Unexpected flags %
  %%%%%%%%%%%%%%%%%%%%
  otherwise
    error(['Unhandled flag = ',num2str(flag)]);

end

% end sfuntmpl

%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(t)

%
% 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 the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;

sizes.NumContStates  = 50;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 41;
sizes.NumInputs      = 32;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;   % at least one sample time is needed

sys = simsizes(sizes);



%
% initialize the initial conditions
%
global XMEAS XMV YP0 NN YY IDV
  NN = 50;
  TIME = t;
  YY = zeros(50,1);
  YP = zeros(50,1);

  

%  TEINIT Subroutine injected into S-function 
%  Command lines for MATLAB:
%  clear all
%  global YY YP;
%  NN = 50;
%  TIME = 0;
%  YY = zeros(50,1);
%  YP = zeros(50,1);
%  TEINIT_3(NN,TIME,YY,YP)
%
%
%        Initialization
% 
%          Inputs:
% 
%            NN   = Number of differential equations
% 
%          Outputs:
% 
%            Time = Current time(hrs)
%            YY   = Current state values
%            YP   = Current derivative values
% 
%       DOUBLE PRECISION XMEAS,XMV

% global IDV 
%       DOUBLE PRECISION G
global G
%       DOUBLE PRECISION
%      .UCLR,UCVR,UTLR,UTVR,
%      .XLR,XVR,ETR,ESR,
%      .TCR,TKR,DLR,
%      .VLR,VVR,VTR,
%      .PTR,PPR,
%      .CRXR,RR,RH,
%      .FWR,TWR,QUR,HWR,UAR,
%      .UCLS,UCVS,UTLS,UTVS,
%      .XLS,XVS,ETS,ESS,
%      .TCS,TKS,DLS,
%      .VLS,VVS,VTS,
%      .PTS,PPS,
%      .FWS,TWS,QUS,HWS,
%      .UCLC,UTLC,XLC,
%      .ETC,ESC,TCC,DLC,
%      .VLC,VTC,QUC,
%      .UCVV,UTVV,XVV,
%      .ETV,ESV,TCV,TKV,
%      .VTV,PTV,
%      .VCV,VRNG,VTAU,
%      .FTM,
%      .FCM,XST,XMWS,
%      .HST,TST,SFR,
%      .CPFLMX,CPPRMX,CPDH,
%      .TCWR,TCWS,
%      .HTR,AGSP,
%      .XDEL,XNS,
%      .TGAS,TPROD,VST
global UCLR UCVR UTLR UTVR XLR XVR ETR ESR...
      TCR TKR DLR VLR VVR VTR PTR PPR CRXR RR RH FWR TWR QUR HWR UAR...
      UCLS UCVS UTLS UTVS XLS XVS ETS ESS TCS TKS DLS...
      VLS VVS VTS PTS PPS FWS TWS QUS HWS UCLC UTLC XLC...
      ETC ESC TCC DLC VLC VTC QUC UCVV UTVV XVV ETV ESV TCV TKV...
      VTV PTV VCV VRNG VTAU FTM FCM XST XMWS...
      HST TST SFR CPFLMX CPPRMX CPDH TCWR TCWS HTR AGSP...
      XDEL XNS TGAS TPROD VST IVST 
	  
 TCR = 0; % put in by MWB, since it is not defined in the program, just initialized.
 TCS = 0; % put in by MWB, since it is not defined in the program, just initialized.
 TCC = 0; % put in by MWB, since it is not defined in the program, just initialized.
 DLR = 0; % put in by MWB, since it is not defined in the program, just initialized.
 DLS = 0; % put in by MWB, since it is not defined in the program, just initialized.
 DLC = 0; % put in by MWB, since it is not defined in the program, just initialized.
 TCV = 0; % put in by MWB, since it is not defined in the program, just initialized.
 HST = zeros(13,1); % put in by MWB, since it is not defined in the program, just initialized.

%       DOUBLE PRECISION
%      .ADIST,
%      .BDIST,
%      .CDIST,
%      .DDIST,
%      .TLAST,
%      .TNEXT,
%      .HSPAN,
%      .HZERO,
%      .SSPAN,
%      .SZERO,
%      .SPSPAN
global ADIST BDIST CDIST DDIST TLAST TNEXT HSPAN...
      HZERO SSPAN SZERO SPSPAN IDVWLK
% 	  DOUBLE PRECISION
%      .AVP,BVP,CVP,
%      .AH,BH,CH,
%      .AG,BG,CG,
%      .AV,
%      .AD,BD,CD,
%      .XMW
global AVP BVP CVP AH BH CH AG BG CG AV...
      AD BD CD XMW
%       DOUBLE PRECISION YY(NN),
%      .YP(NN),
%      .TIME
      XMW(1,1) = 2.0;
      XMW(2,1) = 25.4;
      XMW(3,1) = 28.0;
      XMW(4,1) = 32.0;
      XMW(5,1) = 46.0;
      XMW(6,1) = 48.0;
      XMW(7,1) = 62.0;
      XMW(8,1) = 76.0;
      AVP(1,1) = 0.0;
      AVP(2,1) = 0.0;
      AVP(3,1) = 0.0;
      AVP(4,1) = 15.92;
      AVP(5,1) = 16.35;
      AVP(6,1) = 16.35;
      AVP(7,1) = 16.43;
      AVP(8,1) = 17.21;
      BVP(1,1) = 0.0;
      BVP(2,1) = 0.0;
      BVP(3,1) = 0.0;
      BVP(4,1) = -1444.0;
      BVP(5,1) = -2114.0;
      BVP(6,1) = -2114.0;
      BVP(7,1) = -2748.0;
      BVP(8,1) = -3318.0;
      CVP(1,1) = 0.0;
      CVP(2,1) = 0.0;
      CVP(3,1) = 0.0;
      CVP(4,1) = 259.0;
      CVP(5,1) = 265.5;
      CVP(6,1) = 265.5;
      CVP(7,1) = 232.9;
      CVP(8,1) = 249.6;
      AD(1,1) = 1.0;
      AD(2,1) = 1.0;
      AD(3,1) = 1.0;
      AD(4,1) = 23.3;
      AD(5,1) = 33.9;
      AD(6,1) = 32.8;
      AD(7,1) = 49.9; 
      AD(8,1) = 50.5;
      BD(1,1) = 0.0;
      BD(2,1) = 0.0;
      BD(3,1) = 0.0;
      BD(4,1) = -0.0700;
      BD(5,1) = -0.0957;
      BD(6,1) = -0.0995;
      BD(7,1) = -0.0191;
      BD(8,1) = -0.0541;
      CD(1,1) = 0.0;
      CD(2,1) = 0.0;
      CD(3,1) = 0.0;
      CD(4,1) = -0.0002;
      CD(5,1) = -0.000152;
      CD(6,1) = -0.000233;
      CD(7,1) = -0.000425;
      CD(8,1) = -0.000150;
      AH(1,1) = 1 * 10 ^ (-6);
      AH(2,1) = 1 * 10 ^ (-6);
      AH(3,1) = 1 * 10 ^ (-6);
      AH(4,1) = 0.960 * 10^(-6);
      AH(5,1) = 0.573 * 10^(-6);
      AH(6,1) = 0.652 * 10^(-6);
      AH(7,1) = 0.515 * 10^(-6);
      AH(8,1) = 0.471E-6;
      BH(1,1) = 0.0;
      BH(2,1) = 0.0;
      BH(3,1) = 0.0;
      BH(4,1) = 8.70E-9;
      BH(5,1) = 2.41E-9;
      BH(6,1) = 2.18E-9;
      BH(7,1) = 5.65E-10;
      BH(8,1) = 8.70E-10;
      CH(1,1) = 0.0;
      CH(2,1) = 0.0;
      CH(3,1) = 0.0;
      CH(4,1) = 4.81E-11;
      CH(5,1) = 1.82E-11;
      CH(6,1) = 1.94E-11;
      CH(7,1) = 3.82E-12;
      CH(8,1) = 2.62E-12;
      AV(1,1) = 1.0E-6;
      AV(2,1) = 1.0E-6;
      AV(3,1) = 1.0E-6;
      AV(4,1) = 86.7E-6;
      AV(5,1) = 160.E-6;
      AV(6,1) = 160.E-6;
      AV(7,1) = 225.E-6;
      AV(8,1) = 209.E-6;
      AG(1,1) = 3.411E-6;
      AG(2,1) = 0.3799E-6;
      AG(3,1) = 0.2491E-6;
      AG(4,1) = 0.3567E-6;
      AG(5,1) = 0.3463E-6;
      AG(6,1) = 0.3930E-6;
      AG(7,1) = 0.170E-6;
      AG(8,1) = 0.150E-6;
      BG(1,1) = 7.18E-10;
      BG(2,1) = 1.08E-9;
      BG(3,1) = 1.36E-11;
      BG(4,1) = 8.51E-10;
      BG(5,1) = 8.96E-10;
      BG(6,1) = 1.02E-9;
      BG(7,1) = 0;
      BG(8,1) = 0;
      CG(1,1) = 6.0E-13;
      CG(2,1) = -3.98E-13;
      CG(3,1) = -3.93E-14;
      CG(4,1) = -3.12E-13;
      CG(5,1) = -3.27E-13;
      CG(6,1) = -3.12E-13;
      CG(7,1) = 0;
      CG(8,1) = 0;
      YY(1,1) = 10.40491389;
      YY(2,1) = 4.363996017;
      YY(3,1) = 7.570059737;
      YY(4,1) = 0.4230042431;
      YY(5,1) = 24.15513437;
      YY(6,1) = 2.942597645;
      YY(7,1) = 154.3770655;
      YY(8,1) = 159.1865960;
      YY(9,1) = 2.808522723;
      YY(10,1) = 63.75581199;
      YY(11,1) = 26.74026066;
      YY(12,1) = 46.38532432;
      YY(13,1) = 0.2464521543;
      YY(14,1) = 15.20484404;
      YY(15,1) = 1.852266172;
      YY(16,1) = 52.44639459;
      YY(17,1) = 41.20394008;
      YY(18,1) = 0.5699317760;
      YY(19,1) = 0.4306056376;
      YY(20,1) = 7.9906200783E-03;
      YY(21,1) = 0.9056036089;
      YY(22,1) = 1.6054258216E-02;
      YY(23,1) = 0.7509759687;
      YY(24,1) = 8.8582855955E-02;
      YY(25,1) = 48.27726193;
      YY(26,1) = 39.38459028;
      YY(27,1) = 0.3755297257;
      YY(28,1) = 107.7562698;
      YY(29,1) = 29.77250546;
      YY(30,1) = 88.32481135;
      YY(31,1) = 23.03929507;
      YY(32,1) = 62.85848794;
      YY(33,1) = 5.546318688;
      YY(34,1) = 11.92244772;
      YY(35,1) = 5.555448243;
      YY(36,1) = 0.9218489762;
      YY(37,1) = 94.59927549;
      YY(38,1) = 77.29698353;
      YY(39,1) = 63.05263039;
      YY(40,1) = 53.97970677;
      YY(41,1) = 24.64355755;
      YY(42,1) = 61.30192144;
      YY(43,1) = 22.21000000;
      YY(44,1) = 40.06374673;
      YY(45,1) = 38.10034370;
      YY(46,1) = 46.53415582;
      YY(47,1) = 47.44573456;
      YY(48,1) = 41.10581288;
      YY(49,1) = 18.11349055;
      YY(50,1) = 50.00000000;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -