/* Compute zeroth through kth backward differences *ofthedataintheinputarray
*/
divdif(vec , k, diffn) double vec[]; /* input array of k+1 data items */ double *diffn; /* output array of ith differences */ int k;
{ double diftbl[N]; double *p, *q; double y; int i, o;
/* Copy the given data (zeroth difference) into temp array
*/
p = diftbl;
q = vec; for( i=0; i<=k; i++ )
*p++ = *q++;
/* On the first outer loop, k-1 first differences are calculated. *Theseoverwritetheoriginaldatainthetemparray.
*/
o = k; for( o=k; o>0; o-- )
{
p = diftbl;
q = p; for( i=0; i<o; i++ )
{
y = *p++;
*q++ = *p - y;
}
*diffn++ = *p; /* copy out the last (undifferenced) item */ #if DEBUG
printf( "%.5e ", *p ); #endif
} #if DEBUG
printf( "%.5e\n", *(q-1) ); #endif
*diffn++ = *(q-1);
}
/* Update array of differences, given new data value. *diffnisanarrayofk+1differences,startingwiththe *zerothdifference(thepreviousoriginaldatavalue).
*/
dupdate( diffn, k, f ) registerdouble *diffn; /* input and output array of differences */ int k; /* max order of differences */ double f; /* new data point (zeroth difference) */
{ doublenew, old; int i;
new = f; for( i=0; i<k; i++ )
{
old = *diffn;
*diffn++ = new; #if DEBUG
printf( "%.5e ", new ); #endif new = new - old;
} #if DEBUG
printf( "%.5e\n", new ); #endif
*diffn++ = new;
}
/* Evaluate the interpolating polynomial * *(x-x) *n1 *P(x)=f+--------Df+... *nhn * *(x-x)(x-x)...(x-x) *nn-1n+2-kk-1 *+---------------------------------Df *k-1n *h(k-1)! * * *j *whereDdenotesthejthbackwarddifference,seedupdate(),and * *f=f(x,y(x))istheinterpolatedderivativey'(x). *nnnn * *Thesubroutineargumenttislinearlyscaledsothatt=1.0 *willevaluatethepolynomialatx=x_n+h, *t=0.0correspondstox=x_n,etc.
*/ double difpol( diffn, k, t ) double *diffn; int k; /* differences go up to order k-1 */ double t; /* scaled argument */
{ double f, fac, s, u; int i;
f = *diffn++; /* the zeroth difference = nth data point */
u = 1.0; /*s = x/h - n;*/
s = 1.0; /* to evaluate the polynomial at x = xn + h */
fac = 1.0; for( i=1; i<k; i++ )
{ if( s == 0.0 ) break;
u *= s / fac;
f += u * (*diffn++);
fac += 1.0;
s += 1.0;
} return( f );
}
/* Integrate the interpolating polynomial from x[n] to x[n+1] *toobtainthechangeintheintegratedfunctionfromy[n]toy[n+1] *givenby: * *k-1 *-i *y=y+h>cDf. *n+1n-in *i=0 * *Thissubroutinereturnsthesummationterm,notmultipliedbyh. *Thecoefficientsc_ioftheintegrationformulaareeither *precof[]orcorcof[],givenabove.
*/ double intpol( diffn, coeffs, k ) double *diffn; /* array of backward differences */ double *coeffs; /* coefficients of integration formula */ int k; /* differences used go up to order k-1 */
{ double s; int i;
s = 0.0;
coeffs += k;
diffn += k; for( i=0; i<k; i++ )
{
s += (*--coeffs) * (*--diffn);
} return( s );
}
/* Copy array of n elements from p to q.
*/
vcopy( p, q, n ) registerdouble *p, *q; registerint n;
{ do
*q++ = *p++; while( --n );
}
/* Adams initialization program.
*/
/* Addresses within the work array */ staticdouble *dv; staticdouble *dvp; staticdouble *vp; staticdouble *yp; staticdouble *vn; staticdouble *delta; staticdouble *sdelta; staticdouble *y0;
staticdouble ccor; staticdouble hstep; /* step size (constant) */ staticint order; /* Order of the prediction formula */ staticint ordp1; staticint asiz; staticint dsiz; staticint jstep; /* counts steps taken */
/* Initialize pointers in work array, compute derivatives at *initialposition,andstartthedifferencetables. *neq>=nequatinadstep()below.Ifneq>nequat,unusedspace *isleftforextravariablesthatarenotactuallyintegrated.
*/
adstart( h, yn, work, neq, ord, t ) double h; double yn[], work[]; int neq, ord; double t;
{ double *p; int j;
hstep = h;
ccor = hstep * precof[ord];
jstep = 0;
dsiz = ord + 2;
asiz = neq * dsiz;
order = ord;
ordp1 = ord + 1;
p = work;
dv = p;
p += asiz;
dvp = p;
p += dsiz;
vp = p;
p += neq;
yp = p;
p += neq;
vn = p;
p += neq;
delta = p;
p += neq;
sdelta = p;
p += neq;
y0 = p;
func( t, yn, vn );
p = dv; for( j=0; j<neq; j++ )
{
dupdate( p, 0, vn[j] );
p += dsiz;
}
}
/* Adams-Bashforth-Moulton step.
*/
double adstep( t, yn, nequat ) double *t; double yn[]; int nequat;
{ double e, e0, time; double *pdv; int i, j; double intpol();
time = *t;
jstep += 1;
/* Do Runge-Kutta for the first ord + 1 steps.
*/ if( jstep <= ordp1 )
{
rungek( nequat, time, yn, hstep, yn, delta );
func( time+hstep, yn, vn );
pdv = dv; for( j=0; j<nequat; j++ )
{
dupdate( pdv, jstep, vn[j] );
pdv += dsiz;
}
e = 0.0; goto done;
}
/* Predict the next position *basedoncurrenty'differencetabledv[].
*/
pdv = dv; for( i=0; i<nequat; i++ )
{
yp[i] = yn[i] + hstep * intpol( pdv, precof, order );
pdv += dsiz;
} /* Evaluate derivatives at the predicted position
*/
func( time+hstep, yp, vp );
/* Correct the predicted position and velocity using the derivatives *evalutatedatyp.
*/
pdv = dv; for( i=0; i<nequat; i++ )
{
vcopy( pdv, dvp, dsiz ); /* y' difference table */
dupdate( dvp, ordp1, vp[i] ); /* Note, the following line is equivalent to: *yn[i]=yn[i]+hstep*intpol(dap,corcof,ordp1); *whereeisthecorrectedvalueofthenextvn.
*/
yn[i] = yp[i] + ccor * dvp[order];
pdv += dsiz;
}
/* Evaluate derivative at the final position
*/
func( time+hstep, yn, vn );
e = 0.0;
pdv = dv; for( i=0; i<nequat; i++ )
{
dupdate( pdv, ordp1, vn[i] ); /* Note, the following line is equivalent to: *yn[i]=yn[i]+hstep*intpol(dap,corcof,ordp1); *whereeisthecorrectedvalueofthenextvn.
*/
yn[i] = yp[i] + ccor * pdv[order]; /* Estimate the error
*/
e0 = hstep * pdv[order] * corcof[order]; if( e0 < 0.0 )
e0 = -e0; if( e0 > e )
e = e0;
pdv += dsiz;
}
done:
time += hstep;
*t = time; return( e );
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-14)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.