#include #include #include #include "array_utility.h" /********************************************************************** Given n data points (not equally spaced) of a time function data(time), nderiv finds the dth order numerical derivative of the function at the kth data point. ***********************************************************************/ float nderiv_old(y,x,k,d,n) float *y, *x; int k,d,n; { float u,v,w,dy; int i,j,d2=d/2; if (k=n-d/2) { printf("index %d outside range (%d -- %d)...",k,d/2,n-d/2); pause(); } u=1.0; for (i=1; i<=d2; i++) if (i) u*=(x[k]-x[k-i])*(x[k]-x[k+i]); dy=0; for (i=-d2; i<=d2; i++) { v=1.0; for (j=-d2; j<=d2; j++) if (i!=j) v=v*(x[k+i]-x[k+j]); if (i) dy+=y[k+i]*u/(x[k]-x[k+i])/v; else for (j=-d2; j<=d2; j++) if (j) dy+=y[k]/(x[k]-x[k+j]); } return dy; } float nderiv(y,x,k,d,n) float *x, *y; int k,d,n; { float u,v,dy; int i,j,d2=d/2; u=1.0; for (i=-d2; i<=d2; i++) // common numerator if (k+i>=0 && k+i=0 && k+i=0 && k+j=0 && k+j