function mpc_con

% MPC_CON Show the help for the functions in this toolbox.

% This file is automatically generated.  Matthew Simoneau, 09-04-98
% Copyright (c) 1984-98 by The MathWorks, Inc. All Rights Reserved
% $Revision: 1.8 $ $Date: 1998/10/16 23:19:22 $

helpwin('mpc_con/Contents');

function Contents
%MATLAB Tour Partial Function Help:  mpc_con
%
%Double click on any function for more information
%
%  Model Predictive Control Toolbox.
%  Version 1.0.4 (R11) 03-Sep-1998
% 
%  Identification
%   autosc   - Automatically scales a matrix by its mean and standard deviation.
%   imp2step - Combines MISO impulse response models to form
%                MIMO models in MPC step format.
%   mlr      - Calculates MISO impulse response model via
%                multivariable linear regression.
%   plsr     - Calculates MISO impulse response model via
%                partial least squares regression.
%   rescal   - Converts scaled data back to its original form.
%   scal     - Scale a matrix by specified means and standard deviations.
%   validmod - Validate a MISO impulse response model using new data.
%   wrtreg   - Writes data matrices used for regression.
% 
%  Model Conversions
%   mod2mod  - Changes sampling period of a model in MPC mod format.
%   mod2ss   - Converts a model in MPC mod format to a state-space model.
%   mod2step - Converts a model in MPC mod format to MPC step format.
%   poly2tfd - Converts a transfer function in poly format to MPC tf format.
%   ss2mod   - Converts a state-space model to MPC mod format.
%   ss2step  - Converts a state-space model to MPC step format.
%   tfd2mod  - Converts a model in MPC tf format to MPC mod format.
%   tfd2step - Converts a  model in MPC tf format to MPC step format.
%   th2mod   - Converts a model in the theta format (Identification Toolbox)
% 		into MPC mod format.
% 
%  Model Building - MPC mod format
%   addmod   - Combines two models such that the output of one adds to the
%                input of the other.
%   addmd    - Adds one or more measured disturbances to a plant model.
%   addumd   - Adds one or more unmeasured disturbances to a plant model.
%   appmod   - Appends two models in an unconnected, parallel structure.
%   paramod  - Puts two models in parallel such that they share a common output.
%   sermod   - Puts two models in series.
% 
%  Controller Design and Simulation - MPC step format
%   cmpc     - Solves the quadratic programming problem to simulate performance
% 		of a closed-loop system with input and output constraints.
%   mpccl    - Creates a model in MPC mod format of a closed-loop system with
% 		an unconstrained MPC controller.
%   mpccon   - Calculates the unconstrained controller gain matrix for MPC.
%   mpcsim   - Simulates a closed-loop system with optional saturation
% 		constraints on the manipulated variables.
%   nlcmpc   - S-function for masked block nlcmpc
%   nlmpclib - library which contains masked blocks nlcmpc and nlmpcsim
%   nlmpcsim - S-function for masked block nlmpcsim
% 
%  Controller Design and Simulation - MPC mod format
%   scmpc    - Solves the quadratic programming problem to simulate performance
% 		of a closed-loop system with input and output constraints.
%   smpccl   - Creates a model in MPC mod format of a closed-loop system with
% 		an unconstrained MPC controller.
%   smpccon  - Calculates the unconstrained controller gain matrix for MPC.
%   smpcest  - Designs a state estimator for use in MPC.
%   smpcsim  - Simulates a closed-loop system with optional saturation
% 		constraints on the manipulated variables.
% 
%  Analysis
%   mod2frsp - Calculates frequency response for a system in MPC mod format.
%   smpcgain - Calculates steady-state gain matrix of a system in MPC mod format.
%   smpcpole - Calculates poles of a system in MPC mod format.
%   svdfrsp  - Calculates singular values of a frequency response.
% 
%  Plotting and Matrix Information
%   mpcinfo  - Outputs matrix type and attributes of system representation.
%   plotall  - Plots outputs and inputs from a simulation run on one graph.
%   plotfrsp - Plots the frequency response of a system as a Bode plot.
%   ploteach - Makes separate plots of outputs and/or inputs from a simulation
% 		run.
%   plotstep - Plots the coefficients of a model in MPC step form.
% 
%  Utility Functions
%   abcdchkm - Checks dimensional consistency of A,B,C,D matrices.
%   cp2dp    - Converts from a continuous to a discrete transfer function in
% 		poly format.
%   c2dmp    - Discretize continuous systems.
%   dantzgmp - Solves quadratic programs.
%   dareiter - Solves discrete Riccati equation by an iterative method.
%   dimpulsm - Generates impulse response of discrete system.
%   dlqe2    - Calculates state-estimator gain matrix for discrete systems.
%   dlsimm   - Simulates discrete systems.
%   d2cmp    - Converts discrete systems to continuous systems.
%   mpcaugss - Augments a state-space model with its outputs.
%   mpcparal - Puts two state-space models in parallel.
%   mpcstair - Creates the `stairstep' format used to plot manipulated variables.
%   parpart  - Partition parameters for nlmpcssim and nlcmpc.
%   ss2tf2   - Convert state-space models to transfer functions.
%   tf2ssm   - Convert transfer functions to state-space models.
% 
%-------------------------------------------
%
%  Model Predictive Control Toolbox
% 
%  Demonstrations of using MPC-Tools functions.
%   cmpcex   - cmpc demo
%   demo1dat - simulation data for nlmpcdm1
%   demo2dat - simulation data for nlmpcdm2
%   dlqe2ex  - dlqe2 demo
%   fccdemo  - demo for the FCC control problem
%   idlectr  - demo for the automotive idle speed control problem
%   mlrex    - mlr demo
%   mod2frex - mod2frsp demo
%   mod2ssex - mod2ss demo
%   mod2stex - mod2step demo
%   mpcaugex - mpcaugss demo
%   mpcclex  - mpccl demo
%   mpcconex - mpccon demo
%   mpcplant - S-function of the plant for nlmpcdm1
%   mpcsimex - mpcsim demo
%   nlmpcdm1 - SIMULINK demo for nlmpcsim
%   nlmpcdm2 - SIMULINK demo for nlmpcsim
%   nmpcsim1 - Initialize and run demo1 from MATLAB prompt
%   nmpcsim2 - initialize and run demo2 from MATLAB prompt
%   plsrex   - plsr demo
%   pmlin    - demo for the paper machine control problem using linear model
%   pmnonl   - demo for the paper machine control problem using nonlinear model
%   po2tfdex - poly2tfd demo
%   scmpcex  - scmpc demo
%   scmpcrex - scmpcr demo
%   smpcclex - smpccl demo
%   smpcsmex - smpcsim demo
%   smpccoex - smpccon demo
%   smpcesex - smpcest demo
%   ss2modex - ss2mod demo
%   ss2steex - ss2step demo
%   tfd2mdex - tfd2mod demo
%   tfd2stex - tfd2step demo
%   th2modex - th2mod demo
%   mpctut   - tutorial example
%   mpctutid - tutorial example for identification routines
%   mpctutss - tutorial example for state space models
%   mpctutst - tutorial example for step response models
% 
%  Additional functions used by some demos
% 
%   chknl    - checks simulink plant model for consistency
%   eulerfs  - integration method called by scmpcnl
%   papmach - s-function for nonlinear paper machine plant model
%   scmpcnl  - nonlinear linear version of scmpc (i.e. model/plant could be nonlinear)
%   fccdat   - data file used by fcc_demo
%

function autosc
%MATLAB Tour Partial Function Help:  mpc_con
%
% AUTOSC	Scale a matrix by its means and standard deviations.
% 	[ax,mx,stdx] = autosc(x)
% 
%  Input:
%    x:  input data.
% 
%  Outputs:
%   ax  : scaled data.
%   mx  : mean value of x.  If x is a matrix, it is a row vector
% 	 containing the mean value of each column.
%   stdx: standard deviation of x.  If x is a matrix, it is a row
%         vector containing the standard deviation of each column.
% 
%   

function imp2step
%MATLAB Tour Partial Function Help:  mpc_con
%
% IMP2STEP Generate step response model from impulse response coefficients.
%  	plant = imp2step(delt,nout,theta1,theta2, ...)
% 
%  Inputs:
%   delt: sampling time used for obtaining impulse response coefficients.
%   nout: output stability indicator. For stable systems, this argument
% 	 is set equal to number of outputs, ny. For systems with one
% 	 or more integrating outputs, this argument is a column vector
% 	 of length ny with nout(i)=O indicating an integrating output
% 	 and nout(i)=1 indicating a stable output.
%   theta1, theta2, ...: impulse response coefficient matrices for output
% 	 1, 2, ...  Max. number of thetas which can be supplied is 25.
% 
%  Output:
%   plant: the step response coefficient matrix of dimension (n*ny+ny+2)
% 	  by nu, where n is number of coefficients for each input, and
% 	  ny are number of input and output, respectively.
% 
%  

function mlr
%MATLAB Tour Partial Function Help:  mpc_con
%
% MLR	Determine impulse response coefficients.
%   	 [theta, yres] = mlr(xreg,yreg,ninput)
% 	 [theta, yres] = mlr(xreg,yreg,ninput,plotopt,wtheta,wdeltheta)
%  MLR determines impulse response coefficients for a multi-input
%  single-output system via Multivariable Least Squares Regression or
%  Ridge Regression.
% 
%  Inputs:
%   xreg & yreg: input matrix and output vector produced by function
%                wrtreg or by other means.
%   ninput:  number of input.
%  Optional inputs:
%      plotopt: = 0 (default), no plot is produced;
% 	       = 1, plot of actual output (yreg) and predicted output;
% 	       = 2, plot of yreg and yfit, and plot of residues (yres).
%       wtheta: penalty on theta^2, default = 0.
%    wdeltheta: penalty on the squares of delta theta, default = 0.
% 
%  Outputs:
%   theta: impulse response coeff. matrix.  Each column corresponds to
%   	  impulse response coeff. for a particular input to the output.
%   yres:  residue output or prediction error.
% 
%  

function plsr
%MATLAB Tour Partial Function Help:  mpc_con
%
% PLSR	Determine impulse response coefficients via Partial Least Squares.
%    	[theta,w,cw,ssqdif,yres] = plsr(xreg,yreg,ninput,lv,plotopt)
%  Required Inputs:
%    xreg, yreg: input & output data.
%        ninput: number of input.
%            lv: number of latent vectors, ie., number of directions chosen
%                to maximize the cross variance between the input and output
%                data in PLS routine.
%  Optional Inputs:
%       plotopt = 0 (default), no plot is produced;
% 	       = 1, plot of actual output (yreg) and predicted output;
% 	       = 2, plot of yreg and yfit, and plot of residues (yres).
%  Outputs:
%             w: orthogonal matrix of dimension n by lv consisting of
%        	principle directions maximizing the cross variance between
% 		input and output.  n is number of impulse response coeff.
%            cw: a vector containing coefficients associated with each column
% 	        of w in determining theta.
%         theta: impulse response coefficient matrix of dimension n by nu.
%    		nu is number of inputs. Column i corresponds to the impulse
% 		response coefficients for input i.
%        ssqdif:	percentage variances of input & output captured by PLS.
% 	  yres: residue output.
%  

function rescal
%MATLAB Tour Partial Function Help:  mpc_con
%
% RESCAL Rescale a matrix by specified means and/or standard deviations.
%  	rx = rescal(x,mx)
% 	rx = rescal(x,mx,stdx)
%  If two input arguments are supplied, then x is rescaled by specified
%  means only.
% 
%  Inputs:
%    x  : input data.
%   mx  : means to be used in rescaling.
%   stdx: standard deviations to be used in rescaling.
% 
%  Output:
%     rx: scaled data.
% 
%  

function scal
%MATLAB Tour Partial Function Help:  mpc_con
%
% SCAL	Scale a matrix by specified means and/or standard deviations.
% 	sx = scal(x,mx)
% 	sx = scal(x,mx,stdx)
%  If two input arguments are supplied, then x is scaled by specified
%  means only.
% 
%  Inputs:
%   x   : input data.
%   mx  : means to be used in scaling.
%   stdx: standard deviations to be used in scaling.
% 
%  Output:
%   sx  : scaled data.
% 
%  

function validmod
%MATLAB Tour Partial Function Help:  mpc_con
%
% VALIDMOD Validate the model for a new set of data, xreg & yreg.
% 	yres = validmod(xreg,yreg,theta,plotopt)
% 
%  Required Inputs:
%    xreg, yreg: a new set of data.
%         theta: inpulse response coefficients for the testing model.
% 
%  Optional input:
%       plotopt: = 0 (default), no plot is produced;
% 	        = 1, plot of actual output (yreg) and predicted output;
% 	        = 2, plot of yreg and yfit, and plot of residues (yres).
% 
%  Output:
%      yres:  residue output or prediction error.
% 
%  

function wrtreg
%MATLAB Tour Partial Function Help:  mpc_con
%
% WRTREG	Write regression input and output
% 	[xreg,yreg] = wrtreg(x,y,n)
%  WRTREG writes regression input and output to be used by regression
%  routines in determining the impulse response coefficients. yreg is
%  produced by deleting the first n rows of y, while x is shifted
%  diagonally to produce xreg.
% 
%  Inputs:
%   x,y: input matrix and output vector.
%     n: number of impulse response coefficients for all inputs.
% 
%  Outputs:
%    xreg&yreg:  input matrix and output vector to be used by routines such
%                as pls and mlr.
% 
%  

function mod2mod
%MATLAB Tour Partial Function Help:  mpc_con
%
%  MOD2MOD Change sampling period of model in MPC toolbox MOD format
%   	newmod=mod2mod(oldmod,delt2)
% 
%  Inputs:
%   oldmod  is existing model in MPC toolbox MOD format
%   delt2   is desired new sampling period
% 
%  Output:
%   newmod  is model obtained by converting "oldmod" to
%           sampling period "delt2".  It will also be in the
%           MOD format.
% 
%  

function mod2ss
%MATLAB Tour Partial Function Help:  mpc_con
%
% MOD2SS	Extract state-space matrices from "mod" form
%  	[phi,gam,c,d] = mod2ss(mod)
%  	[phi,gam,c,d,minfo] = mod2ss(mod)
%  	[phi,gam,c,d,minfo,x0,u0,y0,f0] = mod2ss(mod)
% 
%  Input:
%   mod: a plant model in the MPC mod format.
% 
%  Outputs:
%   phi,gam,c,d :  state-space model matrices.
%   minfo       :  ROW vector containing the following information:
%         minfo(1) = T, the sampling period.
%              (2) = n, the system order (dimension of A).
%              (3) = nu, the number of manipulated inputs.
%              (4) = nd, the number of measured disturbances.
%              (5) = nw, the number of unmeasured disturbances.
%              (6) = nym, the number of measured outputs.
%              (7) = nyu, the number of unmeasured outputs.
% 
%   x0,u0,y0,f0 :  linearization data.
% 
%  

function mod2step
%MATLAB Tour Partial Function Help:  mpc_con
%
% MOD2STEP Calculate step response model from a SS model in MPC Mod format.
%      	plant = mod2step(mod,tfinal)
%   	[plant, dplant] = mod2step(mod, tfinal, delt2, nout)
% 
%  Inputs:
%     mod:      appropriate MPC state-space format model of system.
%     tfinal:   truncation time for step response model.
%     delt2:    desired sampling interval for step response model.
%               Optional; default value is minfo(1) of mod.
%     nout:     Optional output stability indicator. For stable systems,
%               set it equal to number of outputs, ny. For systems
%               with one or more integrating outputs, define a
%               vector of length ny with nout(i)=0 indicating an
%               integrating output and nout(i)=1 indicating a stable output.
%               Default value is nout=ny (only stable outputs).
% 
%  Outputs:
%     plant:    step response coefficient matrix to the manipulated
%               variables.
%    dplant:    step response coefficient matrix to the disturbances.
%               Optional.
% 
%  

function poly2tfd
%MATLAB Tour Partial Function Help:  mpc_con
%
% POLY2TFD Create transfer functions in 3 row representation
% 	g = poly2tfd(num,den,delt,delay)
%  POLY2TFD creates a MPC toolbox transfer function in following format:
% 
%  g = [   b0   b1  b2  ... ]   (numerator coefficients)
%      |   a0   a1  a2  ... |   (denominator coefficients)
%      [ delt delay  0  ... ]   (only first 2 elements used in this row)
% 
%  Inputs:
%   num      : Coefficients of the transfer function numerator.
%   den      : Coefficients of the transfer function denominator.
%   delt     : Sampling time.  Can be 0 (for continuous-time system)
%              or > 0 (for discrete-time system).  Default is 0.
%   delay    : Pure time delay (dead time).  Can be >= 0.
%              If omitted or empty, set to zero.
%              For discrete-time systems, enter as PERIODS of pure
%              delay (an integer).  Otherwise enter in time units.

function ss2mod
%MATLAB Tour Partial Function Help:  mpc_con
%
% SS2MOD Convert a state-space model to MPC mod format
%  	pmod = ss2mod(phi,gam,c,d)
%  	pmod = ss2mod(phi,gam,c,d,minfo)
%  	pmod = ss2mod(phi,gam,c,d,minfo,x0,u0,y0,f0)
% 
%  Inputs:
%   phi,gam,c,d : state-space matrices
%   minfo       : a ROW vector containing the following information:
% 
%            minfo(1) = dt, the sampling period.
%                 (2) = n, the system order (dimension of "a").
%                 (3) = nu, the number of manipulated inputs.
%                 (4) = nd, the number of measured disturbances.
%                 (5) = nw, the number of unmeasured disturbances.
%                 (6) = nym, the number of measured outputs.
%                 (7) = nyu, the number of unmeasured outputs.
% 
%   x0,u0,y0,f0 : linearization conditions (optional).  All default
%                 to zero.
% 
%  Output:
%   mod   : model in MPC mod format
% 
%  

function ss2step
%MATLAB Tour Partial Function Help:  mpc_con
%
% SS2STEP Calculate step response model from a continuous or discrete SS model.
%   	plant = ss2step(phi, gam, c, d, tfinal)
%    	plant = ss2step(phi, gam, c, d, tfinal, delt1, delt2, nout)
% 
%  Inputs:
%    phi,gam,c,d:   appropriate state-space realization of system.
%    tfinal:        truncation time for step response model.
%    delt1:         sampling interval of realization. For continuous systems
%                   this argument is set to zero.
%                   Optional: default value is delt1=0.
%    delt2:         desired sampling interval for step response model.
%                   Optional: default value is delt2=delt1 if delt1 is
%                   specified. Otherwise, default value is delt2=1.
%    nout:          output stability indicator. For stable systems, this
%                   argument is set equal to number of outputs, ny. For
%                   systems with one or more integrating outputs, this
%                   argument is a column vector of length ny with nout(i)=0
%                   indicating an integrating output and nout(i)=1
%                   indicating a stable output. Optional: default value is
%                   nout=ny. (only stable outputs).
%  Output:
%    plant:         step response coefficient matrix in MPC step format.
% 
%  

function tfd2mod
%MATLAB Tour Partial Function Help:  mpc_con
%
% TFD2MOD Convert transfer functions (continuous or discrete) to mod format
%  	pmod = tfd2mod(delt2,ny,g1,g2,g3,...,g25)
%  TFD2MOD assumes nd=nw=nyu=0
% 
%  Inputs:
%   delt2   :  sampling period for system.
%   ny      :  number of outputs.
%   gi = [  b0   b1   b2  ... ]   Each gi is a transfer function in the
%        |  a0   a1   a2  ... |   form created by POLY2TFD.  See that
%        [ delt delay  0  ... ]   function for more details.
% 
%  Output:
%   pmod   :  The model in the "mod" format required by MPC toolbox.
% 
%  

function tfd2step
%MATLAB Tour Partial Function Help:  mpc_con
%
% TFD2STEP Determines the step response model of a transfer function model.
%  	plant = tfd2step(tfinal, delt2, nout, g1)
%        plant = tfd2step(tfinal, delt2, nout, g1, ..., g25)
%  The transfer function model can be continuous or discrete.
% 
%  Inputs:
%        tfinal:         truncation time for step response model.
%        delt2:          desired sampling interval for step response model.
%        nout:           output stability indicator. For stable systems, this
%                        argument is set equal to number of outputs, ny.
%                        For systems with one or more integrating outputs,
%                        this argument is a column vector of length ny with
%                        nout(i)=0 indicating an integrating output and
%                        nout(i)=1 indicating a stable output.
%        g1, g2,...:     SISO transfer function described above ordered
%                        to be read in columnwise (by input).  The number of
%                        transfer functions required is ny*nu. (nu=number of
%                        inputs). Limited to ny*nu <= 25.
% 
%  Output:
%        plant:          step response coefficient matrix in MPC step format.
% 
%  

function th2mod
%MATLAB Tour Partial Function Help:  mpc_con
%
% TH2MOD Converts from the ID "theta" format to the MPC mod format.
% 
%  	      umod  = th2mod(th)
% 	[umod,emod] = th2mod(th1,th2,th3,th4,th5,th6,th7,th8)
% 
%  Inputs:
%   th   model in the theta format.  Each additional input
%        is assumed to model a new output which is placed in
%        parallel with the preceding outputs.  These are the
%        inputs to "umod", whose dynamics depend on the A, B
%        and F polynomials of the theta model(s).  An optional
%        noise model ("emod") is created in which each output
%        is affected by an independent noise input, and whose
%        dynamics depends on the A, C and D polynomials of the
%        theta model(s).
% 
%  Outputs:
%   umod : Model of effect of measured inputs on outputs, in MPC
%          MOD format.
%   emod : Model of effect of noise on outputs, in MPC
%          MOD format.

function addmod
%MATLAB Tour Partial Function Help:  mpc_con
%
%  ADDMOD Add outputs of "mod2" to the manipulated inputs of "mod1"
%         pmod=addmod(mod1,mod2)
%  The outputs of "mod2" are added to the manipulated inputs of "mod1"
%  to form the composite model "pmod".  Thus, all inputs
%  of "mod1" and "mod2" are retained in the composite model, but
%   its only outputs will be those of "mod1".
%  The number of outputs of "mod2" must equal the number of manipulated
%  variables of "mod1".  "mod1" and "mod2" must have been created using
%  the same sampling period.
% 
%  Inputs:
%   mod1  is a plant model in the MPC mod format.
%   mod2  is a plant model in the MPC mod format.
% 
%  Outputs:
%   pmod  is the composite model in the MPC mod format.
% 
%  

function addmd
%MATLAB Tour Partial Function Help:  mpc_con
%
%  ADDMD	Add a measured disturbance model to a plant model.
%        model=addmd(pmod,dmod)
%  ADDMD creates a composite model in which the outputs
%  are the sum of the outputs of pmod and dmod.  The inputs
%  of the composite model are the manipulated variables from
%  pmod, followed by the inputs to dmod (which are all classified
%  as measured disturbances in the composite model), followed by
%  the unmeasured disturbances from pmod (if any).
% 
%  Inputs:
%   pmod  is the plant model in the MPC mod format.
%   dmod  is the disturbance model in the MPC mod format.
% 
%  Outputs:
%   model is the composite model in the MPC mod format.
% 
%  

function addumd
%MATLAB Tour Partial Function Help:  mpc_con
%
%  ADDUMD Add an unmeasured disturbance model to a plant model.
%         model=addumd(pmod,dmod)
%  ADDUMD creates a composite model in which the outputs
%  are the sum of the outputs of pmod and dmod.  The inputs
%  of the composite model are the manipulated variables from
%  pmod, followed by the measured disturbances from pmod (if any),
%  followed by the inputs to dmod (which are all classified
%  as unmeasured disturbances in the composite model).
% 
%  Inputs:
%   pmod  is the plant model in the MPC mod format.
%   dmod  is the disturbance model in the MPC mod format.
% 
%  Outputs:
%  model  is the composite model in the MPC mod format.
% 
%  

function appmod
%MATLAB Tour Partial Function Help:  mpc_con
%
%  APPMOD Append two models together to form an aggregate model.
%         pmod=appmod(mod1,mod2)
%    OR   [pmod,in1,in2,out1,out2]=appmod(mod1,mod2)
%  Models "mod1" and "mod2" are appended to form a composite,
%  "pmod".  All models are in the MOD format.  Inputs and
%  outputs are grouped by type, with those from mod1 of a given
%  type preceding those from mod2 of the same type.
% 
%  Inputs:
%   mod1  first model in the MPC mod format.
%   mod2   second model in the MPC mod format.
% 
%  Outputs:
%   pmod is the composite of mod1 and mod2 in the MPC mod format.
%   in1,in2,out1,out2 are optional index vectors that point to the
%        new locations of the original inputs and outputs in pmod.
%        For example, in1(i) is the "pmod" input number of
%        input i from mod1, and out2(j) is the pmod output number
%        of output j from mod2, etc.
% 
%  

function paramod
%MATLAB Tour Partial Function Help:  mpc_con
%
% PARAMOD Put two models in parallel by connecting their outputs.
%         pmod=paramod(mod1,mod2)
%  PARAMOD mimics the "parallel" function of the Control Systems
%  toolbox for system descriptions in the MPC format.  The
%  output of "pmod" will be the sum of the outputs of "mod1"
%  and "mod2".  The different input types (manipulated
%  variables, measured disturbances (if any) and unmeasured
%  disturbances (if any) are grouped in "pmod" such that those
%  for "mod1" precede those for "mod2".
% 
%  Inputs:
%   mod1  is a plant model in the MPC mod format.
%   mod2  is a plant model in the MPC mod format.
% 
%  Output:
%   pmod  is the composite model in the mod MPC format.
% 
%  

function sermod
%MATLAB Tour Partial Function Help:  mpc_con
%
% SERMOD	Put two models in series.
%     	pmod=sermod(mod1,mod2)
%  SERMOD mimics the "series" function of the Control Systems
%  Toolbox for models in the MPC mod format.  "mod" is a combined
%  model in which the MEASURED outputs of "mod1" are the manipulated
%  variable inputs to "mod2".  The disturbance inputs to "mod1" and
%  "mod2" are retained as disturbance inputs to "mod".
% 
%  Inputs:
%   mod1  is a plant model in the MPC mod format.
%   mod2  is a plant model in the MPC mod format.
% 
%  Output:
%   pmod  is the composite model in the MPC mod format.
% 
%  

function cmpc
%MATLAB Tour Partial Function Help:  mpc_con
%
% CMPC	Simulation of the constrained Model Predictive Controller.
% 	 [y,u,ym] = cmpc(plant, model, ywt, uwt,M,P, tend, r, ulim,ylim,...
%                         tfilter, dplant, dmodel, dstep)
%  REQUIRED INPUTS:
%  plant (model): step response coefficient matrix of the plant (model).
%  ywt: weight matrix for the difference between the output variables and the
%       reference trajectory in the objective function.
%  uwt: weight matrix for the man. variable move in the objective function
%  M: If M contains only one element it is the input horizon. If M contains
%     more than one element then each element specifies blocking intervals.
%  P: number of steps in the time horizon for the quadratic objective function.
%     P = Inf indicates the infinite control horizon.
%  tend: final time of simulation.
%  r: a constant or time-varying reference trajectory.
%  OPTIONAL INPUTS:
%  ulim: matrix of manipulated variable constraints.  It is a trajectory of
%        lower limits (Ulow), upper limits (Uhigh) and rate of change (DelU).
%        If there are no constraints or usat=[], ulim is set appropriately.
%  ylim: matrix of output variable constraints. It is a trajectory of lower
%        (Ylow) and upper limits (Yhigh) on the output variables. Default=[].
%  tfilter:  time constants for noise filter and unmeasured disturbance lags.
%            Default is no filtering and step disturbance.
%  dplant: step response coefficient matrix for the disturbance effect on the
%          plant output.If dplant is provided, dstep is required.Default=[].
%  dmodel: step response coefficient matrix for the measured disturbance effect
%          on the model output. If dmodel is provided, dstep is also required.
%          Default=[].
%  dstep: For output step disturbances it is a trajectory of disturbance values
%         For disturbances through step response models,it is a trajectory of
%         disturbance model inputs.Default value is the empty matrix,[].
%  OUTPUT ARGUMENTS: y (system response) , u (manipulated variables) and
%                    ym (model response)
%  

function mpccl
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCCL	Combine a plant STEP model and a controller STEP model.
%    	[clmod,cmod]=mpccl(plant,model,Kmpc,tfilter,dplant,dmodel)
%  MPCCL	combines a plant STEP model and a controller STEP model.
%  yielding a closed-loop system model in the MPC MOD format.
%  Required Inputs:
%   plant  the plant model in the STEP format.
%   model  the internal model in the STEP format.
%   Kmpc   the controller gain matrix created by MPCCON.
%  Optional Inputs:
%   tfilter matrix of filter time constants and noise dynamics.
% 	   If omitted or set to an empty matrix, the default is to
% 	   use the DMC estimator.
%   dplant  model in STEP format representing all the disturbances
% 	   (measured and unmeasured) that affect the plant.
% 	   If omitted or set to an empty matrix, the default is that
% 	   there are no disturbances.
%   dmodel  model in STEP format representing the measured disturbances.
% 	   If omitted or set to an empty matrix, the default is that
% 	   there are no measured disturbances. See the documentation
% 	   for the function MPCSIM for more details on how disturbances
% 	   are handled when using step-response models.
%  Outputs:
%   clmod  the resulting closed-loop system model in the MOD format.
%   cmod   the dynamic model of the controller in the MOD format (optional).
%  

function mpccon
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCCON	Calculate MPC controller gains for unconstrained case.
% 	Kmpc = mpccon(model,ywt,uwt,M,P)
%  MPCCON uses a step-response model of the process.
% 
%  Inputs:
%   model   : Step response coefficient matrix of model.
%   ywt,uwt : matrices of constant or time-varying weights.
%             If the trajectory is too short, they are kept constant
%             for the remaining time steps.
%   M       : number of input moves and blocking specification.  If
%             M contains only one element it is the input horizon
%             length.  If M contains more than one element
%             then each element specifies blocking intervals.
%   P       : output (prediction) horizon length.  P = Inf indicates the
% 	     infinite horizon.
% 
%  Output:
%   Kmpc	   : Controller gain matrix
% 
%  

function mpcsim
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCSIM	Simulation of the unconstrained Model Predictive Controller.
%  	[y,u,ym] = mpcsim(plant, model, Kmpc, tend, r,usat, tfilter,
%                                  dplant, dmodel, dstep)
%  REQUIRED INPUTS:
%  plant(model): the step response coefficient matrix of the plant (model)
%                generated by the function tfd2step.
%  Kmpc: the constant control law matrix computed by the function mpccon
%        (closed-loop simulations).For open-loop simulation, controller=[].
%  tend: final time of simulation.
%  r: for the closed-loop simulation, it is a constant or time-varying
%     reference trajectory. For the open-loop simulation, it is the
%     trajectory of the manipulated variable u.
%  OPTIONAL INPUTS:
%  usat: the matrix of manipulated variable constraints.It is a constant
%        or time-varying trajectory of the lower limits (Ulow), upper limits
%        (Uhigh) and  rate  of  change  limits  (DelU)  on  the manipulated
%        variables. Default=[].
%  tfilter:  time constants for noise filter and unmeasured disturbance lags.
% 	    Default is no filtering and step disturbance.
%  dplant: step response coefficient matrix for the disturbance effect on the
%          plant output generated by the function tfd2step.  If distplant is
%          provided, dstep is also required. Default = [].
%  dmodel: step response coefficient matrix for the measured disturbance
%          effect on the model output generated by the function tfd2step.
%          If distmodel is provided, dstep is also required. Default=[].
%  dstep: matrix of disturbances to the plant.  For output step disturbances
%         it is a constant or time-varying trajectory of disturbance  values
%         For disturbances through step response models,it is a constant or
%         time-varying trajectory of disturbance model inputs.Default=[].
%  OUTPUT ARGUMENTS: y (system response), u (manipulated variable) and
%                    ym (model response)
%  

function nlcmpc
%MATLAB Tour Partial Function Help:  mpc_con
%
% 
% NLCMPC S-function for SIMULINK block nlcmpc.

function nlmpclib
%MATLAB Tour Partial Function Help:  mpc_con
%
%nlmpclib is a Simulink model

function nlmpcsim
%MATLAB Tour Partial Function Help:  mpc_con
%
% 
% NLMPCSIM S-function for SIMULINK block nlmpcsim.

function scmpc
%MATLAB Tour Partial Function Help:  mpc_con
%
% SCMPC Simulate CL systems for constrained problems.
%  	[y,u,ym]=scmpc(pmod,imod,ywt,uwt,M,P,tend, ...
%                  r,ulim,ylim,Kest,z,v,w,wu)
%  SCMPC designs an MPC-type controller for constrained problems
%  and simulates the closed-loop system with hard constraints
%  (inputs and outputs) using quadratic programming.
%  NOTE:  This version does not anticipate setpoint changes.  The
%         current setpoint is assumed to be constant over the
%         prediction horizon.
%         See SCMPCR for an alternative approach.
%  Inputs:
%   pmod: plant model in MOD format
%   imod: internal model in MOD format -- used as basis for
%         controller design.
%   ywt:  Penalty weighting for setpoint tracking.
%   uwt:  Penalty weighting for changes in manipulated variables.
%   M:    Number of moves OR sequence of blocking factors.
%   P:    Length of prediction horizon.
%   tend: duration of the simulation.
%   r:    setpoint sequence, one column for each output.
%   ulim: [Ulow Uhigh delU].  NOTE:  delU must be finite.
%   ylim: [Ylow Yhigh].
%   Kest: Estimator gain matrix.
%   z:    Measurement noise.
%   v:    Measured disturbance (for feedforward control).
%   w:    General unmeasured disturbance.
%   wu:   Unmeasured disturbance added to manipulated variables.
%  Outputs: y (system response), u (manipulated variables),
% 	   ym (model response).
%  

function smpccl
%MATLAB Tour Partial Function Help:  mpc_con
%
% SMPCCL Create a model of the closed-loop system for simulations.
%     	[clmod,cmod]=smpccl(pmod,imod,Ks)
%     	[clmod,cmod]=smpccl(pmod,imod,Ks,Kest)
%  NOTE:  assumes measured disturbances and setpoints
%  will be constant in the future.
% 
%  Inputs:
%   pmod   the plant model in the MOD format.
%   imod   the internal model in the MOD format.
%   Ks     the controller gain matrix created by SMPCCON
%   Kest   the estimator gain matrix.  If omitted or Kest=[],
%          the MPC default estimator gain is used.
% 
%  Outputs:
%   clmod  the resulting closed-loop system model in the
%          MOD format.
%   cmod   the dynamic model of the controller in the MOD
%          format (optional).
% 
%  

function smpccon
%MATLAB Tour Partial Function Help:  mpc_con
%
% SMPCCON Calculate MPC controller gains for unconstrained case.
%  	Ks = smpccon(imod,ywt,uwt,M,P)
%  SMPCCON Uses a state-space model of the process.
% 
%  Inputs:
%   imod   : Model of plant to be used as state estimator and for gain
%            for gain calculation (mod form).
%   ywt,uwt: matrices of constant or time-varying weights.
%            If the trajectory is too short, it is kept constant
%            for the remaining time steps.  For 'shifted' and
%            'blocked' data.
% 
%             |yw1(1) . . . ywny(1)|           |uw1(1) . . . uwnu(1)|
%   ywt   =   |  .            .    |    uwt =  |  .            .    |
%             |yw1(P) . . . ywny(P)|           |uw1(M) . . . uwnu(M)|
% 
%         where nu, ny are number of man. vars. and outputs respectively
%   M    :number of input moves and blocking specification.  If
%         M contains only one element it is the input horizon
%         length.  If M contains more than one element
%         then each element specifies blocking intervals.
%   P    :output (prediction) horizon length
% 
%  Output:
%    Ks  :Controller gain matrix = [Kr, Kx, Kv].
% 
%  

function smpcest
%MATLAB Tour Partial Function Help:  mpc_con
%
% SMPCEST Design a state estimation gain matrix for use in MPC.
% 	[Kest,newmod]=smpcest(imod,tau,signoise);
% 	Kest=smpcest(imod,Q,R)
%  Inputs:
%    imod  is the internal model for which the estimator
%          is to be designed (in the MPC format).
%     tau  Is the vector of time constants (continuous time)
%          characterizing the disturbances affecting each measured
%          output.  Setting an element equal to zero is equivalent
%          to the DMC assumption.  Setting one to "inf" is equivalent
%          to assuming that random ramps affect that output.  Setting
%          tau=[] or omitting it gives DMC for all outputs.
% signoise is the signal-to-noise ratio affecting each output.  Must
%          be between "inf" (no noise) and zero (no signal).
%        Q is the covariance of the unmeasured disturbances in imod.
%        R is the covariance of the measurement noise.
%  Outputs:
%    Kest is the resulting estimator gain.
%  newmod is the modified version of the input model, which contains
%         new states to represent disturbances (if any of the TAU values
%         are non-zero).
%  

function smpcsim
%MATLAB Tour Partial Function Help:  mpc_con
%
% SMPCSIM Simulate closed-loop systems with saturation constraints.
% 	[y,u,ym]=smpcsim(pmod,imod,Ks,tend,r,ulim,Kest,z,v,w,wu)
%  State-space closed-loop simulation for MPC with saturation
%  constraints on manipulated variables.  Otherwise, unconstrained.
% 
%  Inputs:
%   pmod:     plant model in MOD format
%   imod:     internal model in MOD format -- used as basis for
%             controller design.
%   Ks:       MPC controller gain, calculated using SMPCCON.
%   tend:     duration of the simulation.
%   r:        setpoint sequence, one column for each output.
%   ulim:     0 or [] for no constraint, or [ Ulow Uhigh delU].
%   Kest:     Estimator gain matrix.
%   z:        Measurement noise.
%   v:        Measured disturbance (for feedforward control).
%   w:        General unmeasured disturbance.
%   wu:       Unmeasured disturbance added to manipulated variables.
% 
%  Outputs: y (system response), u (manipulated variables),
% 	   ym (model response)
% 
%  

function mod2frsp
%MATLAB Tour Partial Function Help:  mpc_con
%
% MOD2FRSP Complex frequency response of a matrix in MPC mod format
% 	[frsp,eyefrsp] = mod2frsp(mod,freq,out,in,balflg)
% 
%    Complex frequency response of a matrix in MPC mod format, produces
%    a VARYING matrix which contains its frequency response:
% 
%     mod     - matrix in MOD format
%     freq    - row vector with lower power of 10, upper power of 10
%               and number of frequency points (0 --> matlab default=50)
%     out     - row vector of which outputs to use in response
%               (it uses all outputs as default or if out == [])
%     in      - row vector of which inputs to use in response
%               (it uses all inputs as default or if in == [])
%     balflg  - if nonzero balances PHI matrix prior to eval, zero (default)
%               value for BALFLG leaves state-space unchanged
%     frsp    - VARYING frequency response matrix
%     eyefrsp - I-FRSP VARYING frequency response matrix if square matrix
% 
%  

function smpcgain
%MATLAB Tour Partial Function Help:  mpc_con
%
% SMPCGAIN Calculate the steady state gain matrix for "mod"
%   	g=smpcgain(mod)
% 
%  Input:
%   mod    : plant model in the MPC mod format;
%            must be open-loop stable
% 
%  Output:
%   g      : matrix in which the rows correspond to the outputs
%             and the columns to the inputs
% 
%  

function smpcpole
%MATLAB Tour Partial Function Help:  mpc_con
%
% SMPCPOLE Calculate poles for plant model in the MPC format.
%  	[poles]=smpcpole(mod)
% 
%  Input:
%   mod     :  is a plant model in the MPC mod format.
% 
%  Output:
%   poles   :  is the vector of complex values - poles
% 
%  

function svdfrsp
%MATLAB Tour Partial Function Help:  mpc_con
%
% SVDFRSP SVD at each frequency of the frequency response generated by MOD2FRSP
% 	[sigma,omega]=svdfrsp(vmat)
%        Given a varying matrix vmat, svdfrsp calculates the singular
% 	values of each submatrix in vmat. The output sigma is a matrix
% 	of singular values, whose ith row contains the singular values
% 	of the ith submatrix in order of decreasing magnitude. The output
% 	omega is a column vector containing the independent variable
% 	values in vmat.
% 
%  

function mpcinfo
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCINFO Return information about a matrix.
% 	flag=mpcinfo(mat).
%  Type of matrix is determined.  Types include constant matrix,
%  system matrix, varying matrix, matrix in MPC Mod format or
%  matrix in MPC Step format.
% 
%  Input:
%   mat:	the matrix to be checked.
% 
%  Output:
%  flag < 0   Normal (constant) matrix.
%       = 1   System matrix used in mu-tools
%       = 2   Varying matrix.
%       = 4   MPC "mod" format.
%       = 5   MPC "step" format.

function plotall
%MATLAB Tour Partial Function Help:  mpc_con
%
% PLOTALL Plot manipulated and controlled variables on one "page".
%         []=plotall(y,u)
%         []=plotall(y,u,t)
%  Plots y and u in separate graphs versus time.  Converts
%  u to a stairstep form before plotting.  If y (or u)
%  has more than 1 column, all will be plotted on the same
%  graph.  If the scalings are very different, this may not be
%  satisfactory.  In that case, use PLOTEACH.
% 
%  Inputs:
%      y    matrix of outputs
%      u    matrix of manipulated variables
%      t    if supplied as scalar, then sampling period
%           if supplied as column vector, then times when
%           samples of y and u where taken.
% 
%  

function plotfrsp
%MATLAB Tour Partial Function Help:  mpc_con
%
% PLOTFRSP Plot the frequency response generated by MOD2FRSP as a Bode plot.
% 	plotfrsp(vmat)
%   	plotfrsp(vmat,out,in)
%  PLOTFRSP generates Bode plots of the elements of the frequency dependent
%  matrix, say F(w), whose sampled values are contained in the VARYING matrix
%  vmat. The optional arguments OUT and IN  are row vectors of row and
%  column indices respectively, and may be used to obtain the Bode plots of
%  only the elements of the corresponding submatrix of F(w).
% 
%  

function ploteach
%MATLAB Tour Partial Function Help:  mpc_con
%
% PLOTEACH Plot each y and each u separately
%    	ploteach(y)
%    	ploteach([],u)
%    	ploteach(y,u)
%    	ploteach(y,[],t)
%   	ploteach(y,u,t)
%  Up to four plots are be plotted on a screen
% 
%  Inputs:
%   y : outputs
%   u : manipulated variables
%   t : time interval or sequence of times
% 
%  [Hy,Hu]=ploteach(y,u,t) returns handles of the figure windows
%  containing y and u, respectively.
% 
%  

function plotstep
%MATLAB Tour Partial Function Help:  mpc_con
%
% PLOTSTEP Plot the step response of a system.
%  	plotstep(plant)
%   	plotstep(plant,opt)
% 
%  Inputs:
%   plant : description of the system in MPC step format.
%   opt   : a vector indicating which outputs to plot.
% 
%  

function abcdchkm
%MATLAB Tour Partial Function Help:  mpc_con
%
% ABCDCHKM Check whether the entered system is valid.
% 	msg = abcdchkm(a,b,c,d)
% 
%  msg = empty if system is ok; otherwise msg tells what is wrong
%  with the system.

function cp2dp
%MATLAB Tour Partial Function Help:  mpc_con
%
% CP2DP	Convert a continuous SISO transfer function to discrete.
% 	[numd,dend]=cp2dp(num,den,delt,delay)
% 
%  CP2DP converts a continuous SISO transfer function with numerator
%  and denominator polynomials "num" and "den", respectively,
%  into the corresponding discrete-time versions, "numd" and "dend".
%  "delt" is the sampling period.
%  "delay" is the time delay (>= 0) in same units as "delt".
% 
%  

function c2dmp
%MATLAB Tour Partial Function Help:  mpc_con
%
% C2DMP	Discretization of a Continuous Time System
% 
% 	[Phi, Gam, f0] = c2dmp(A,B,T,dx0)
% 
%        Continuous System :  dx/dt  = A*x + B*u + dx0
%        Discrete System   :  x(k+1) = Phi*x(k) + Gam*u(k) + f0
%        Sample Time       :  T
% 
%        dx0 and f0 are optional and default to zero.  They
%        may be non-zero when a linear model is obtained by
%        linearization at an unsteady condition.

function dantzgmp
%MATLAB Tour Partial Function Help:  mpc_con
%
%  DANTZGMP Solve quadratic program.
%  	[bas,ib,il,iter,tab]=dantzgmp(tabi,basi,ibi,ili)
% 
%  Inputs:
%   tabi      : initial tableau
%   basi      : initial basis
%   ibi       : initial setting of ib
%   ili       : initial setting of il
% 
%  Outputs:
%   bas       : final basis vector
%   ib        : index vector for the variables -- see examples
%   il        : index vector for the lagrange multipliers -- see examples
%   iter      : iteration counter
%   tab       : final tableau

function dareiter
%MATLAB Tour Partial Function Help:  mpc_con
%
% DAREITER Discrete-time algebraic Riccati equation solver.
%        X = dareiter(F, G1, G2, H)
%  	DAREITER uses an iterative doubling algorithm and returns
% 	the stabilizing solution (if it exists) to the discrete-time
% 	Riccati equation:
% 
%          F' X F - X - F' X G1 (G2 + G1' X G1)^(-1) G1' X F + H = 0
% 
%        assuming G is symmetric and nonnegative definite and H is
%        symmetric.
% 

function dimpulsm
%MATLAB Tour Partial Function Help:  mpc_con
%
% DIMPULSE Impulse response of discrete-time linear systems.
%        [y,x] = dimpulsm(A,B,C,D,iu,n);
%        [y,x] = dimpulsm(num,den,n);
%  DIMPULSM simulates the response of the discrete system:
%            x[k+1] = Ax[k] + Bu[k]
%            y[k]   = Cx[k] + Du[k]
%       or
% 	    y(z) = num(z)/den(z) u(z)
%   to an unit sample applied to the single input IU.  The number of
%   points is N. When invoked without left hand
%   arguments, DIMPULSM plots the response on the screen.
% 
%  Note: this function is similar to dimpulse in Control Toolbox.

function dlqe2
%MATLAB Tour Partial Function Help:  mpc_con
%
% DLQE2	Get solution of Kalman Filter equations by iteration.
%         k=dlqe2(phi,gamw,c,q,r)
%         [k,m,p]=dlqe2(phi,gamw,c,q,r)
%  Usage is identical to the DLQE routine in the Control Toolbox,
%  but DLQE2 can handle systems in which phi is singular, e.g.,
%  systems with pure time delay.
% 
%  Inputs:
%   phi   is phi of a plant model in the MPC format.
%   gamw  is gamma for unmeasured disturbances (w)
%   c     is c of a plant model in the MPC format.
%   q     is the unmeasured disturbance noise covariance matrix
%   r     is the measurement noise covariance matrix
% 
%  Outputs:
%   k  Optimal steady-state gain for discrete Kalman filter.
%   m  Expected covariance of the errors in state estimates
%      before measurement update.
%   p  Expected covariance of the errors in state estimates
%      after measurement update.
% 
%  

function dlsimm
%MATLAB Tour Partial Function Help:  mpc_con
%
% DLSIMM  Simulation of discrete-time linear systems.
% 	[y,x] = dlsimm(A,B,C,D,u,x0);
% 	[y,x] = dlsimm(num,den,u);
% 
% Simulates the time response of the discrete system:
% 		x[n+1] = Ax[n] + Bu[n]
%  		y[n]   = Cx[n] + Du[n]
% 	or
% 		y(z) = num(z)/den(z) u(z)
% 
%  The initial condition x0 is optional.  When invoked without left
%  arguments, DLSIMM plots the time response on the screen.

function d2cmp
%MATLAB Tour Partial Function Help:  mpc_con
%
% D2CMP	Convert from discrete to continuous systems
% 	[A,B] = d2cmp(Phi,Gam,T)
% 
%        Discrete System   : x(k+1)  = Phi*x(k) + Gam*u(k)
%        Continuous System : dx/dt   = Ax + Bu
%        Sample Time (ZOH) : T
% 

function mpcaugss
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCAUGSS Augment a state space model with the output variables.
%         [phia,gama,ca]=mpcaugss(phi,gam,c)
%         [phia,gama,ca,da,na]=mpcaugss(phi,gam,c,d)
%  The new states are the differences in the old states
%  augmented by the outputs.  The inputs are all differenced.
%  The d matrix is optional.  The default is zero.
% 
%  Inputs:
%   phi  is phi of a plant model in the MPC format.
%   gam  is gam of a plant model in the MPC format.
%   c    is c of a plant model in the MPC format.
%   d    is d of a plant model in the MPC format.
% 
%  outputs:
%   phia  is phi of a plant model in the MPC format.
%   gama  is gam of a plant model in the MPC format.
%   ca    is c of a plant model in the MPC format.
%   da    is d of a plant model in the MPC format.

function mpcparal
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCPARAL  Parallel connection of two state-space systems.
% 	[A,B,C,D] = MPCPARAL(A1,B1,C1,D1,A2,B2,C2,D2)  produces a state-space
% 	system consisting of the parallel connection of systems 1 and 2
% 	such that Y = Y1 + Y2.  The resulting system is:
% 		 .
% 		|x1| = |A1 0| |x1| + |B1 0| |u1|
% 		|x2|   |0 A2| |x2| + |0 B2| |u2|
% 
% 		|y| = y1+y2 = |C1 C2| |x1| + |D1 D2| |u1|
% 				                    |x2|           |u2|
% 
% NOTE:  Same as old version of PARALLEL in the Control Toolbox.

function mpcstair
%MATLAB Tour Partial Function Help:  mpc_con
%
% MPCSTAIR Turns an array into a stair-step function for plotting.
% 
% 	out=mpcstair(in)
% 
% Rows of "in" are assumed to contain the function at successive
% time points.
% 
% If "istime" is supplied as non-zero, "in" is assumed to be a
% time vector.  The result is then a "stairstep" time vector
% that can be used when plotting a stairstep function.

function parpart
%MATLAB Tour Partial Function Help:  mpc_con
%
%  PARPART  Parameter partition for nlmpcsim and nlcmpc.
%  	y = parpart(x1,x2)
% 	y = parpart(x1,x2,x3)
%   PARPART(x1,x2) = [x1 x2].  If x1 and x2 do not have
%   the same number of rows, PARPART appends extra rows
%   with the last row of x1 or x2.  If x1 is an integer,
%   x1 is the number of outputs from the plant and no output
%   constraints are assumed.  If x2 is an integer, x2 is
%   the number of inputs and no input constraints are assumed.
%   PARPART(x1,x2,x3) = [x1 x2 x3].  If x1, x2, and x3 do not
%   have the same number of rows, PARPART appends extra rows
%   with the last row of x1, x2, or x3.
% 
%  

function ss2tf2
%MATLAB Tour Partial Function Help:  mpc_con
%
% SS2TF2 Obtain the transfer function of a SS model (one at a time)
% 	[Num,Den] = ss2tfs(A,B,C,D,iu)
%  Num is a matrix containing as many rows as there are outputs
%  Den is the denominator polynomial
%  The state space system is given by:
%               x(k+1) = A*x(k) + B*u(k)
%               y(k)   = C*x(k) + D*u(k)
%  iu is the input to be used.  The transfer function can
%  only be computed between the outputs and one input at a
%  time due to MATLAB limitations
% 

function tf2ssm
%MATLAB Tour Partial Function Help:  mpc_con
%
% TF2SSM	Construct a SS realization of a transfer function
% 	[A,B,C,D] = tf2ssm(Num, Den)
% 
%        Y(s) = H(s)u(s)
%        H(s) = Num(s)/Den(s)
%        Y(s) may Contain More than one Output so Num(s) may contain
%        more than one row.
%        u(s) is scalar (due to MATLAB limitations)
%        Den(s) is the common denominator of all h(s)
% 
%        The Realization is :
%                 x(k+1) = A*x(k) + B*u(k)
%                 y(k)   = C*x(k) + D*u(k)
% 

function cmpcex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function demo1dat
%MATLAB Tour Partial Function Help:  mpc_con
%
%   data for nlmpcdm1.
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function demo2dat
%MATLAB Tour Partial Function Help:  mpc_con
%
%   data for nlmpcdm2
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function dlqe2ex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function fccdemo
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function idlectr
%MATLAB Tour Partial Function Help:  mpc_con
%
% 
%   Example on idle speed control problem.
% 
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mlrex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mod2frex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mod2ssex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mod2stex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpcaugex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpcclex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpcconex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpcplant
%MATLAB Tour Partial Function Help:  mpc_con
%
% 
%   s-function for the demo plant -- a CSTR
% 
%   The system dynamics can be described as follows:
%      		dT/dt =  - 1.2 T + Ti + 0.2 Tst
%    		dh/dt =  - 1/1.5 h + fi
%      with the initial condition
% 		T(0)  = 58.33333    (u(1))
% 		h(0)  = 1.5         (u(2))
% 		Tst(0)= 100
% 		fi(0) = 1
% 		Ti(0) = 50

function mpcsimex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function nlmpcdm1
%MATLAB Tour Partial Function Help:  mpc_con
%
%nlmpcdm1 is a Simulink model

function nlmpcdm2
%MATLAB Tour Partial Function Help:  mpc_con
%
%nlmpcdm2 is a Simulink model

function nmpcsim1
%MATLAB Tour Partial Function Help:  mpc_con
%
% 
%   This program tests the nonlinear version of mpcsim (mpcsim-simulink).
% 

function nmpcsim2
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Matrices of the linearized paper machine model

function plsrex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function pmlin
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function pmnonl
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Matrices of the linearized paper machine model

function po2tfdex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function scmpcex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function scmpcrex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function smpcclex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function smpcsmex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function smpccoex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function smpcesex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function ss2modex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function ss2steex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function tfd2mdex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function tfd2stex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function th2modex
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpctut
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpctutid
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpctutss
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function mpctutst
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function chknl
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Checks SIMULINK plant model for consistency with a model in the
%  MPC mod format, assuming that they both represent the same
%  plant.  If OK, returns number of plant input and output variables.
%  Otherwise stops with an error message.  PMOD is the SIMULINK plant
%  model and MINFOI is the MINFO vector (MOD format) for the
%  internal model.  Called by SCMPCNL.
% 
%  INP and OUTP are the number of plant inputs and outputs, and
%  x0 is the initial plant state.

function eulerfs
%MATLAB Tour Partial Function Help:  mpc_con
%
%  function [ttab,xtab]=eulerfs(plant,t,x0,u0,h,p1,p2,p3,p4,p5)
%  Copyright (c) 1994-98 by The MathWorks, Inc.
%  $Revision: 1.8 $

function papmach
%MATLAB Tour Partial Function Help:  mpc_con
%
%  [sys,x0,xstr,TS]=papmach(t,x,u,flag,xp0)
% 
%  SIMULINK representation of the paper machine process described
%  by Ying, Rao, and Sun, Chem. Eng. Communications, 1992.  (See
%  also, Proceedings of American Control Conference, San Diego,
%  pp 1917, 1990).  The model is bilinear.  Using nomenclature in
%  the paper, process variables are:
% 
%  Manipulated variables:   Gp, Gw
%  Measured disturbance:    Np
%  Unmeasured disturbance:  Nw
%  Measured outputs:        H2, N1, N2
%  Unmeasured outputs:      H1
%  States:                  H1, H2, N1, N2
% 
%  Accepts standard Simulink inputs for a system model.
%  The model expects the input vector (u)
%  to contain [Gp, Gw, Np, Nw] (in that order).
%  The outputs will be H2, N1, N2 (in that order).
%  Use optional parameter xp0 to initialize the state.
%  The default initial condition is zero.

function scmpcnl
%MATLAB Tour Partial Function Help:  mpc_con
%
%  Designs an MPC-type controller for constrained problems.
%  Simulates the closed-loop system with hard constraints
%  (inputs and outputs) using quadratic programming.
%  This version uses a SIMULINK plant model that can include
%  nonlinear dynamics, etc.
% 
%  NOTE:  use EULERFS function to integrate the plant equations.
%  Assumes ALL inputs are constant over each sampling
%  period.  If you have SIMULINK, substitute RK45 or equivalent
%  for the EULERFS function for faster execution and better
%  reliability.
% 
%  ---------usage------------------
% 
%  [y,u,ym,x]=scmpcnl(pmod,imod,ywt,uwt,blocks,p,tend, ...
%                         setpts,ulim,ylim,Kest,ydist,mdist, ...
%                         umdist,udist,x0,u0,hint)
% 
% pmod:     plant model in SIMULINK format
% imod:     internal model in MOD format -- used as basis for 
%           controller design.
% ywt:      Penalty weighting for setpoint tracking.
% uwt:      Penalty weighting for changes in manipulated variables.
% M:        Number of moves OR sequence of blocking factors.
% P:        Length of prediction horizon.
% tend:     duration of the simulation.
% r:        setpoint sequence, one column for each output.
% ulim:     [ Ulow Uhigh delU].  NOTE:  delU must be finite.
% ylim:     [ Ylow Yhigh].
% Kest:     Estimator gain matrix.
% z:        Measurement noise.
% v:        Measured disturbance (for feedforward control).
% w:        General unmeasured disturbance.
% wu:       Unmeasured disturbance added to manipulated variables.
% x0:       Initial states of plant (optional).
% u0:       Initial KNOWN plant inputs (optional).  Must include 
%           manipulated variables and measured disturbances, if any.
% hint:     Fixed step size for integration of nonlinear ODEs.
% x:        Optional output -- state trajectory of plant.

