MEX file that calculates the aproximation to the Jacobian matrix of the closed loop fuzzy system usign finite differences.
MATLAB help:
% APROXJAC Calculates the closed loop Jacobian matrix usign finite differences.
%
% J = aproxjac(X, Plant, Controller)
%
% J = aproxjac(X, Plant, Controller, h)
%
% Arguments:
%
% X -> State vector.
%
% Plant -> Fuzzy model of the Plant.
%
% Controlador -> Fuzzy model of the Controller.
%
% h -> Increment. Default value is 0.001;
%
% J -> Jacobian matrix of the closed loop fuzzy system.
%
% ( df1 dfn )
% 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, aproxlinear, conseq2mat, fis2txt, fuz2mat,
% fuzcomb, fuzeval, fuzjac, 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,model;
double *X,*J,*d,h;
if(nrhs!=3 && nrhs!=4)
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 %lu.\n",E_Model, model);
}
}
if ((nrhs==3) && n!=S[0].outputs())
if ((nrhs==2) && n!=S[0].inputs())
Array2D<double> Jac(n,n);
if (nrhs==4)
{
h = *mxGetPr(prhs[3]);
if (h<=0)
}
else
if (!Jac.dim1())
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++;
}
}
}