Computational routine
eng


tanhblk

File content


/* Modnumlib Scicos interfacing function
 * Copyright (C) 2009-2011 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.
 */
 
/* tanhblk Scicos hyperbolic tangent block
 * Type 2 simulation function ver 1.0 - scilab-2.6&2.7
 * 13 octobre 2003 - IRCOM GROUP - Author : A.Layec
 */

/* REVISION HISTORY :
 * $Log$
 */

#include<math.h>

#include "machine.h"

/* Ce bloc réalise l'opération y[0]=rpar[0]*tanh(rpar[1]*u[0])
 * entrées régulières : vecteur des entrées u[0..nu-1]
 * sorties régulières : vecteurs des sorties y[0..nu-1]
 * entrées et sorties d'évenement : néant
 * paramètres rélls rpar[0..nu-1] : vecteur du gain
 *                  rpar[nu..2*nu-1] : vecteur du coefficient
 */

/*prototype*/
void tanhblk(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;
 double t1,t2;
 int i,nu;

 /*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*/
 nu=insz[0];

 for(i=0;i<nu;i++)
 {
  t1=exp(rpar[nu+i]*u[i]);
  t2=exp(-rpar[nu+i]*u[i]);
  y[i]=rpar[i]*((t1-t2)/(t1+t2));
 }
}