#include #include #include #include /* #include */ #include "xpplim.h" /* #include "browse.h" */ extern int ConvertStyle; extern FILE *convertf; double get_ivar(); #define MAXMARK 200 #define IA 16807 #define IM 2147483647 #define AM (1.0/IM) #define IQ 127773 #define IR 2836 #define NTAB 32 #define NDIV (1+(IM-1)/NTAB) #define EPS 1.2e-12 #define RNMX (1.0-EPS) #define PI 3.1415926 int myrandomseed=-1; double ndrand48(); double ran1(); double evaluate(); double new_state(); double atof(); extern int DCURY; extern int *my_ode[]; extern char *ode_names[MAXODE]; extern int NMarkov,FIX_VAR,NODE,NEQ; extern double MyData[MAXODE]; extern int NLINES; extern char *save_eqn[1000]; extern int RandSeed; typedef struct { int **command; char **trans; double *fixed; int nstates; double *states; int type; /* 0 is default and state dependent. 1 is fixed for all time */ char name[12]; } MARKOV; MARKOV markov[MAXMARK]; extern float **storage; int storind; float *my_mean[MAXODE],*my_variance[MAXODE]; int stoch_len; int STOCH_FLAG,STOCH_HERE,N_TRIALS; int Wiener[MAXPAR]; int NWiener; double normal(); extern double constants[]; add_wiener(index) int index; { Wiener[NWiener]=index; NWiener++; } set_wieners(dt,x,t) double dt; double *x,t; { int i; update_markov(x,t,fabs(dt)); for(i=0;i=MAXMARK){ printf("Too many Markov chains...\n"); exit(0); } markov[j].nstates=nstates; markov[j].states=(double *)malloc(nstates*sizeof(double)); if(type==0){ markov[j].trans=(char **)malloc(n2*sizeof(char*)); markov[j].command = (int **)malloc(n2*sizeof(int*)); } else { markov[j].fixed=(double *)malloc(n2*sizeof(double)); } for(i=0;i0){ ninv=1./(float)(N_TRIALS); for(i=0;i g); } else { if (xm != oldm) { oldm=xm; sq=sqrt(2.0*xm); alxm=log(xm); g=xm*alxm-gammln(xm+1.0); } do { do { y=tan(PI*ndrand48()); em=sq*y+xm; } while (em < 0.0); em=floor(em); t=0.9*(1.0+y*y)*exp(em*alxm-gammln(em+1.0)-g); } while (ndrand48() > t); } return em; } double ndrand48() { return ran1(&myrandomseed); } nsrand48(int seed) { myrandomseed=-seed; } double ran1(idum) long *idum; { int j; long k; static long iy=0; static long iv[NTAB]; double temp; if (*idum <= 0 || !iy) { if (-(*idum) < 1) *idum=1; else *idum = -(*idum); for (j=NTAB+7;j>=0;j--) { k=(*idum)/IQ; *idum=IA*(*idum-k*IQ)-IR*k; if (*idum < 0) *idum += IM; if (j < NTAB) iv[j] = *idum; } iy=iv[0]; } k=(*idum)/IQ; *idum=IA*(*idum-k*IQ)-IR*k; if (*idum < 0) *idum += IM; j=iy/NDIV; iy=iv[j]; iv[j] = *idum; if ((temp=AM*iy) > RNMX) return RNMX; else return temp; } #undef IA #undef IM #undef AM #undef IQ #undef IR #undef NTAB #undef NDIV #undef EPS #undef RNMX