MEX file that calculates the Jacobian matrix of the closed loop fuzzy system.
MATLAB help:
% FUZJAC Calculates the Jacobian matrix of the closed loop fuzzy system.
%
% J = fuzjac(X, Plant, Controller)
%
% Arguments:
%
% X -> State vector where the
jacobian matrix is calculated.
%
% Plant -> Fuzzy model of the Plant.
%
% Controlador -> Fuzzy model of the Controller.
%
% J -> Jacobian matrix of closed loop system.
%
% ( df1 df1 )
% dx1 | ----- ... ----- |
% ----- = f1(x) | dx1 dxn |
% dt | |
% ... J = | ... ... ... |
% dxn | |
% ----- = fn(x) | dfn dfn |
% dt | ----- ... ----- |
% ( dx1 dxn )
% x = [ x1 ; x2 ; ... ; xn]
%
% Fuzzy_Model -> This fuzzy model could be a '.txt' file, a '.fis' file,
% or a 'FIS' variable from MATLAB Workspace.
%
% See also activation, antec2mat, aproxjac, aproxlinear, conseq2mat, fis2txt,
% fuz2mat, fuzcomb, fuzeval, fuzlinear, fuzprint, mat2antec, mat2conseq,
% mat2fuz, fuzsubsystem, txt2fis
Source code:
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
size_t i,q,n;
int model;
double *X,*J,*d;
if(nrhs!=3)
if (nlhs>1)
for (i=0;i<nrhs;i++)
if (mxIsEmpty(prhs[i]) || mxIsNaN(*mxGetPr(prhs[i])))
X = mxGetPr(prhs[0]);
if (!X)
n = mxGetM(prhs[0]);
if (mxGetN(prhs[0])!=1)
for (model=1;model<3;model++)
{
{
sprintf(error,"%s %d.\n",E_Model, model);
}
}
if ((nrhs==3) && n!=S[0].outputs())
if ((nrhs==2) && n!=S[0].inputs())
Array2D<double> Jac =
jacobian(S[0], S[1], X);
if (!Jac.dim1())
{
mxDestroyArray(plhs[0]);
}
plhs[0] = mxCreateDoubleMatrix(n,n,mxREAL);
J = mxGetPr(plhs[0]);
if (!J)
{
mxDestroyArray(plhs[0]);
}
for (i=0;i<n;i++)
{
for (q=0;q<n;q++)
{
*J = Jac[q][i];
J++;
}
}
}