Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <nag.h>
- #include <stdio.h>
- #include <nag_stdlib.h>
- #include <nagd02.h>
- #include <nagx01.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- static void NAG_CALL fcn(Integer neq, double x, double eps, const double y[],
- double f[], Nag_User *comm);
- static void NAG_CALL g(Integer neq, double eps, const double ya[],
- const double yb[], double bc[], Nag_User *comm);
- #ifdef __cplusplus
- }
- #endif
- #define NEQ 2
- #define MNP 40
- #define Y(I, J) y[(I) *tdy + J]
- int main()
- {
- static Integer use_comm[6] = {1, 1, 1, 1, 1, 1};
- 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);
- comm.p = (Pointer)&use_comm;
- neq = NEQ;
- mnp = MNP;
- if (neq >= 1)
- {
- if (!(abt = NAG_ALLOC(neq, double)) ||
- !(x = NAG_ALLOC(mnp, double)) ||
- !(y = NAG_ALLOC(neq*mnp, double)))
- {
- printf("Allocation failure\n");
- exit_status = -1;
- goto END;
- }
- tdy = mnp;
- }
- else
- {
- exit_status = 1;
- return exit_status;
- }
- tol = 1.0e-4;
- np = 17;
- numbeg = 1;
- nummix = 0;
- x[0] = 0.0;
- x[np-1] = nag_pi;
- deleps = 0.1;
- nag_ode_bvp_fd_nonlin_gen(neq, &deleps, fcn, numbeg, nummix, g,
- Nag_DefInitMesh, mnp, &np, x, y, tol, abt, NULLFN,
- NULLFN, NULLFN, NULLFN, &comm, &fail);
- if (fail.code != NE_NOERROR)
- {
- printf("Error from nag_ode_bvp_fd_nonlin_gen (d02rac).\n%s\n",
- fail.message);
- exit_status = 1;
- goto END;
- }
- printf("Solution on final mesh of %"" points \n", np);
- printf(" X Y(1) Y(2) Y(3)\n");
- for (j = 0; j < np; ++j)
- {
- printf(" %9.3f ", x[j]);
- for (i = 0; i < neq; ++i)
- printf(" %9.4f", Y(i, j));
- printf("\n");
- }
- printf("\n\nMaximum estimated error by components \n");
- for (i = 1; i <= 3; ++i)
- printf(" %11.2e", abt[i-1]);
- printf(" \n");
- END:
- NAG_FREE(abt);
- NAG_FREE(x);
- NAG_FREE(y);
- return exit_status;
- }
- static void NAG_CALL fcn(Integer neq, double x, double eps, const double y[],
- double f[], Nag_User *comm)
- {
- Integer *use_comm = (Integer *)comm->p;
- if (use_comm[0])
- {
- printf("(User-supplied callback fcn, first invocation.)\n");
- use_comm[0] = 0;
- }
- f[0] = -y[1];
- f[1] = y[0];
- }
- static void NAG_CALL g(Integer neq, double eps, const double ya[],
- const double yb[], double bc[], Nag_User *comm)
- {
- Integer *use_comm = (Integer *)comm->p;
- if (use_comm[1])
- {
- printf("(User-supplied callback g, first invocation.)\n");
- use_comm[1] = 0;
- }
- bc[0] = yb[0]-0;
- bc[1] = ya[1]-1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement