Computational routine
eng
systemg
/* Modnumlib Scicos interfacing function
* Copyright (C) 2009 Alan Layec
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* systemg Scicos Chua sub-systeme G block
* Type 2 simulation function ver 1.0 - scilab-2.6&2.7&3.0
* 19 novembre 2003 - IRCOM GROUP - Author : A.Layec
*/
/* REVISION HISTORY :
* $Log$
*/
#include "machine.h"
#define Abs(x) ( ( (x) >= 0) ? (x) : -( x) )
/* Cette fonction de simulation réalise le sous-système G
* du circuit de Chua:
*
* y=x
* dx/dt=A*((u-x)-Gb*x+1/2*(Ga-Gb)*(abs(u+E)-abs(u-E)))
*
* où A, Ga et Gb sont des vecteurs de paramètres réels,
* E=1 et u est le vecteurs des entrées, y le vecteur des sorties
* x le vecteur de la variable d'état
*
* Entrée régulière : u[0..nu-1] : vecteur des entrées
* Sortie régulière : y[0..nu-1] : vecteur des sorties
* Entrée évènementielle : néant (héritage)
* sortie évènementielle : néant
* paramètres : rpar[0..nu-1] vecteur A
* rpar[nu..2*nu-1] vecteur Ga
* rpar[2*nu..3*nu-1] vecteur Gb
* etat continu : x[0..nu-1] vecteur de la variable d'état x
*/
/*prototype*/
void systemg(flag,nevprt,t,xd,x,nx,z,nz,tvec,ntvec,rpar,nrpar,
ipar,nipar,inptr,insz,nin,outptr,outsz,nout)
integer *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar,insz[],*nin,outsz[],*nout;
double x[],xd[],z[],tvec[],rpar[];
double *inptr[],*outptr[],*t;
{
/*déclaration des variables*/
double *y;
double *u;
int nu,i;
/*récupération des adresses des ports réguliers*/
y=(double *)outptr[0];
u=(double *)inptr[0];
/*récupération de la taille du port d'entrée u*/
nu = insz[0];
/*Le flag 1 place l'état continu x dans le reg y*/
if(*flag==1||*flag==6)
{
for(i=0;i<nu;i++) y[i]=x[i];
}
/*Le flag 0 calcule la dérivée de l'état continu*/
else if(*flag==0)
{
for(i=0;i<nu;i++)
xd[i]=rpar[i]*((u[i]-x[i])-((rpar[2*nu+i]*x[i])+0.5*(rpar[nu+i]-rpar[2*nu+i])*(Abs(x[i]+1)-Abs(x[i]-1))));
}
}