/* nag_check_deriv_1 (c05zcc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 7 revised, 2001. * Mark 8 revised, 2004. */ #include #include #include #include #ifdef __cplusplus extern "C" { #endif static void f(Integer n, double xc[], double fvecc[], double fjacc[], Integer tdj, Integer *userflag, Nag_User *comm); #ifdef __cplusplus } #endif int main(void) { #define FJAC(I,J) fjac[(I)*tdfjac + J] Integer exit_status=0, i, j, n, tdfjac; NagError fail; Nag_User comm; double *fjac=0, *fvec=0, *x=0; INIT_FAIL(fail); Vprintf("nag_check_deriv_1 (c05zcc) Example Program Results\n"); n = 3; if (n>0) { if ( !( fjac = NAG_ALLOC(n*n, double)) || !( fvec = NAG_ALLOC(n, double)) || !( x = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdfjac = n; } else { Vprintf("Invalid n.\n"); exit_status = 1; return exit_status; } /* Set up an arbitrary point at which to check the 1st derivatives */ x[0] = 9.2e-01; x[1] = 1.3e-01; x[2] = 5.4e-01; Vprintf("The test point is "); for (j=0; j0) fvec[k] -= x[k-1]; if (k0) FJAC(k,k-1) = -1.0; if (k