#define S_FUNCTION_NAME MFAC // phi(k)=…=phi(k+p)
#define S_FUNCTION_LEVEL 2
#define N 2 // \tau_bar=N-1, the control prediction horizon U[0:N-1]
//#define SAMPLETIME 0.01
/*
- Need to include simstruc.h for the definition of the SimStruct and
- its associated macro definitions.
*/
#include “simstruc.h”
/*====================*
- S-function methods *
*====================*/
double rho, lambda; //eta0, mu0, phik0,
/* Function: mdlInitializeSizes ===============================================
- Abstract:
- The sizes information is used by Simulink to determine the S-function
- block’s characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct S)
{
/ See sfuntmpl_doc.c for more details on the macros below */
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1+1+1+N+1); // timestamp/ phik/ yk/ r(k+1),...,r(k+tau_bar+1) / u(k-1)
ssSetInputPortRequiredContiguous(S, 0, true);
/*
* Set direct feedthrough flag (1=yes, 0=no).
* A port