www.pudn.com > communicationmatlab.rar > ARYSIN.C
/* * ARYSIN array sin computation. * * Syntax: [sys, x0] = arysin(t,x,u,flag,Func) * where Func is the computation function to be specified. * the size of the output array is the same as the size * of the input array. * Wes Wang 5/11/94 * Copyright (c) 1994-96 The MathWorks, Inc. * All Rights Reserved * $Revision: 1.1 $ $Date: 1996/04/01 19:02:22 $ */ /* specify the name of this S-Function. */ #define S_FUNCTION_NAME arysin /* Defines for easy access the matrices which are passed in */ #define NUM_ARGS 1 #define FUN_NAME ssGetArg(S, 0) /* include simstruc.h for the definition of the SimStruct and macro definitions. */ #include#ifdef MATLAB_MEX_FILE #include #endif #include #include "simstruc.h" #ifdef MATLAB_MEX_FILE #include "mex.h" #endif /* * mdlInitializeSizes - initialize the sizes array */ static void mdlInitializeSizes (S) SimStruct *S; { ssSetNumContStates( S, 0); /* number of continuous states */ ssSetNumDiscStates( S, 0); /* number of discrete states */ ssSetNumInputs ( S, -1); /* number of inputs */ ssSetNumOutputs ( S, -1); /* number of outputs */ ssSetDirectFeedThrough(S, 1); /* direct feedthrough flag */ ssSetNumSampleTimes( S, 1); /* number of sample times */ ssSetNumInputArgs( S, NUM_ARGS);/* number of input arguments */ ssSetNumRWork( S, 0); /* number of real work vector elements */ ssSetNumIWork( S, 0); /* number of integer work vector elements */ ssSetNumPWork( S, 0); /* number of pointer work vector elements */ } /* * mdlInitializeSampleTimes - initialize the sample times array * * This function is used to specify the sample time(s) for your S-function. * If your S-function is continuous, you must specify a sample time of 0.0. * Sample times must be registered in ascending order. */ static void mdlInitializeSampleTimes(S) SimStruct *S; { ssSetSampleTimeEvent(S, 0, 0.0); ssSetOffsetTimeEvent(S, 0, 0.0); } /* * mdlInitializeConditions - initialize the states * Initialize the states, Integers and real-numbers */ static void mdlInitializeConditions(x0, S) double *x0; SimStruct *S; { } /* * mdlOutputs - compute the outputs * * In this function, you compute the outputs of your S-function * block. The outputs are placed in the y variable. */ static void mdlOutputs(y, x, u, S, tid) double *y, *x, *u; SimStruct *S; int tid; { int inSize, i; char funct[3]; for (i=0; i < 3; i++) funct[i] = (char)mxGetPr(FUN_NAME)[i]; inSize = ssGetNumInputs(S); /* mexPrintf(funct); */ if ((funct[0]== 's') && (funct[1] == 'i')) { /* sin function */ for (i=0; i < inSize; i++) y[i] = sin(u[i]); } else if ((funct[0]== 'c') && (funct[1] == 'o')) { /* cos function */ for (i=0; i < inSize; i++) y[i] = cos(u[i]); } else if ((funct[0]== 't') && (funct[1] == 'a')) { /* tan function */ for (i=0; i < inSize; i++) y[i] = tan(u[i]); } else if ((funct[0]== 'e') && (funct[1] == 'x')) { /* exp function */ for (i=0; i < inSize; i++) y[i] = exp(u[i]); } else if ((funct[0]== 'a') && (funct[1] == 's')) { /* asin function */ for (i=0; i < inSize; i++) y[i] = asin(u[i]); } else if ((funct[0]== 'a') && (funct[1] == 'c')) { /* acos function */ for (i=0; i < inSize; i++) y[i] = acos(u[i]); } else if ((funct[0]== 'a') && (funct[1] == 't')) { /* atan function */ for (i=0; i < inSize; i++) y[i] = atan(u[i]); } else if ((funct[0]== 'l') && (funct[1] == 'n')) { /* ln function */ for (i=0; i < inSize; i++) y[i] = log(u[i]); } else if ((funct[0]== 'l') && (funct[1] == 'o')) { /* log10 function */ for (i=0; i < inSize; i++) y[i] = log10(u[i]); } else if ((funct[0]== 's') && (funct[1] == 'q')) { /* sqrt function */ for (i=0; i < inSize; i++) { if (u[i] > 0) y[i] = sqrt(u[i]); else if (u[i] < 0) y[i] = -sqrt(-u[i]); else y[i] = 0; } } else if ((funct[0]== 's') && (funct[1] == 'g')) { /* sgn function */ for (i=0; i< inSize; i++) { if (u[i] < 0) y[i] = -1.; else y[i] = 1.; } } else if ((funct[0]== 'r') && (funct[1] == 'o')) { /* round to the nearest integers */ for (i=0; i = .5) { y[i] = (double) ceil(u[i]); } } } else if ((funct[0]== 'f') && (funct[1] == 'l')) { /* floor */ for (i=0; i