int AutoRegression( double *inputseries, int length, int degree, double *coefficients, int method) { double mean; int i, t; double *w=NULL; /* Input series - mean */ double *h=NULL; double *g=NULL; /* Used by mempar() */ double *per=NULL; double *pef=NULL; /* Used by mempar() */ double **ar=NULL; /* AR coefficients, all degrees */ /* Allocate space for working variables */ if ((w = (double *)malloc(length*sizeof(double))) == NULL) { fprintf(stderr,"Unable to malloc memory - fatal!\n"); exit(-1); } if ((h = (double *)malloc((degree+1)*sizeof(double))) == NULL) { fprintf(stderr,"Unable to malloc memory - fatal!\n"); exit(-1); } if ((g = (double *)malloc((degree+2)*sizeof(double))) == NULL) { fprintf(stderr,"Unable to malloc memory - fatal!\n"); exit(-1); } if ((per = (double *)malloc((length+1)*sizeof(double))) == NULL) { fprintf(stderr,"Unable to malloc memory - fatal!\n"); exit(-1); } if ((pef = (double *)malloc((length+1)*sizeof(double))) == NULL) { fprintf(stderr,"Unable to malloc memory - fatal!\n"); exit(-1); } if ((ar = (double **)malloc((degree+1)*sizeof(double*))) == NULL) { fprintf(stderr,"Unable to malloc memory - fatal!\n"); exit(-1); } for (i=0;i max) { max = h; maxi = j; } } if (maxi != i) { mswap = mat[i]; mat[i] = mat[maxi]; mat[maxi] = mswap; vswap = vec[i]; vec[i] = vec[maxi]; vec[maxi] = vswap; } hvec = mat[i]; pivot = hvec[i]; if (fabs(pivot) == 0.0) { fprintf(stderr,"Singular matrix - fatal!\n"); return(FALSE); } for (j=i+1;j=0;i--) { hvec = mat[i]; for (j=n-1;j>i;j--) vec[i] -= (hvec[j] * vec[j]); vec[i] /= hvec[i]; } return(TRUE); }