/* nag_ode_ivp_adams_interp(d02qzc) Example Program * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 6 revised, 2000. * Mark 7 revised, 2001. * */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static void ftry03(Integer neqf, double x, double y[], double yp[], Nag_User *comm); #ifdef __cplusplus } #endif #define NEQF 2 #define TSTART 0.0 int main(void) { double atol[NEQF], rtol[NEQF], y[NEQF], ywant[NEQF], ypwant[NEQF]; Boolean crit, alter_g, vectol, one_step, sophist; double t, tinc, tout, tcrit, twant, hmax, pi; Integer max_step, i, j, neqf, neqg, nwant; Nag_Start state; Nag_ODE_Adams opt; static NagError fail; fail.print = TRUE; Vprintf("d02qzc Example Program Results\n"); pi = X01AAC; state = Nag_NewStart; neqf = NEQF; neqg = 0; sophist = FALSE; vectol = TRUE; for (i = 0; i < 2; ++i) { atol[i] = 1e-08; rtol[i] = 0.0001; } one_step = TRUE; crit = TRUE; tinc = pi * 0.0625; tcrit = tinc * 8.0; tout = tcrit; max_step = 500; hmax = 2.0; t = TSTART; twant = TSTART + tinc; nwant = 2; y[0] = 0.0; y[1] = 1.0; Vprintf("\n T Y(1) Y(2)\n"); Vprintf(" %6.4f %7.4f %7.4f \n",t, y[0], y[1]); d02qwc(&state, neqf, vectol, atol, rtol, one_step, crit, tcrit, hmax, max_step, neqg, &alter_g, sophist, &opt, &fail); j = 1; while (t < tout && fail.code == NE_NOERROR) { d02qfc(neqf, ftry03, &t, y, tout, NULLDFN, NAGUSER_DEFAULT, &opt, &fail); while (twant <= t && fail.code == NE_NOERROR) { d02qzc(neqf, twant, nwant, ywant, ypwant, &opt, &fail); Vprintf(" %6.4f %7.4f %7.4f \n",twant, ywant[0], ywant[1]); ++j; twant = (double)j*tinc + 0.0; } } /* Free the memory which was allocated by * d02qwc to the pointers inside opt. */ d02qyc(&opt); if (fail.code == NE_NOERROR) return EXIT_SUCCESS; else return EXIT_FAILURE; } static void ftry03(Integer neqf, double x, double y[], double yp[], Nag_User *comm) { yp[0] = y[1]; yp[1] = -y[0]; } /* ftry03 */