/* nag_ode_bvp_fd_nonlin_gen (d02rac) Example Program. * * Copyright 1992 Numerical Algorithms Group. * * Mark 3, 1992. * Mark 7 revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #ifdef __cplusplus extern "C" { #endif static void fcn(Integer neq, double x, double eps, double y[], double f[], Nag_User *comm); static void g(Integer neq, double eps, double ya[], double yb[], double bc[], Nag_User *comm); static void jaceps(Integer neq, double x, double eps, double y[], double f[], Nag_User *comm); static void jacgep(Integer neq, double eps, double ya[], double yb[], double bcep[], Nag_User *comm); static void jacobf(Integer neq, double x, double eps, double y[], double f[], Nag_User *comm); static void jacobg(Integer neq, double eps, double ya[], double yb[], double aj[], double bj[], Nag_User *comm); #ifdef __cplusplus } #endif #define NEQ 3 #define MNP 40 #define Y(I,J) y[(I)*tdy + J] int main(void) { double *abt=0; double deleps; double tol; double *x=0, *y=0; Integer exit_status=0; Integer i, j; Integer np; Integer numbeg, nummix; Integer neq, mnp, tdy; Nag_User comm; NagError fail; INIT_FAIL(fail); Vprintf("nag_ode_bvp_fd_nonlin_gen (d02rac) Example Program Results\n"); Vprintf("\nCalculation using analytic Jacobians\n\n"); neq = NEQ; mnp = MNP; if (neq>=1) { if ( !( abt = NAG_ALLOC(neq, double)) || !( x = NAG_ALLOC(mnp, double)) || !( y = NAG_ALLOC(neq*mnp, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdy = mnp; } else { exit_status = 1; return exit_status; } tol = 1.0e-4; np = 17; numbeg = 2; nummix = 0; x[0] = 0.0; x[np-1] = 10.0; deleps = 0.1; /* nag_ode_bvp_fd_nonlin_gen (d02rac). * Ordinary differential equations solver, for general * nonlinear two-point boundary value problems, using a * finite difference technique with deferred correction */ nag_ode_bvp_fd_nonlin_gen(neq, &deleps, fcn, numbeg, nummix, g, Nag_DefInitMesh, mnp, &np, x, y, tol, abt, jacobf, jacobg, jaceps, jacgep, &comm, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_ode_bvp_fd_nonlin_gen (d02rac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("Solution on final mesh of %ld points \n", np); Vprintf(" X Y(1) Y(2) Y(3)\n"); for (j=0; j< np; ++j) { Vprintf(" %9.3f ", x[j]); for (i=0; i