home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ANUMR5.ZIP / EDICSTST.C < prev    next >
C/C++ Source or Header  |  1991-11-25  |  2KB  |  123 lines

  1. #include <math.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6.  
  7. #include "anum.h"
  8. #include "sysio.h"
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. /* Differential equation are defined as follows :
  17.  
  18.  
  19.     x' = f(v)
  20.      n
  21.  
  22.     with v = (t, x , x , ..., x , ..., x    )
  23.           1   2        n        nbeq
  24.  
  25. */
  26.  
  27. double f1(double *v)
  28.  
  29. {    return(*(v+2));
  30. }
  31.  
  32.  
  33. double f2(double *v)
  34.  
  35. {    return(sin((*v)*5)*9.0/2.0 - 16*(*(v+1)));
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42. void results(int order, int nret, double *matsol)
  43.  
  44. {    int i,j;
  45.  
  46.     for (i=0; i<order; i++)
  47.     {    printf("\n       T          X[%d]       \n",i+1);
  48.           puts("------------------------------");
  49.           for (j=0; j<nret; j++)
  50.             printf("% 10.5le  % 10.5le\n",
  51.                 *(matsol+j*(order+1)),
  52.                 *(matsol+j*(order+1)+i+1));
  53.     }
  54. }
  55.  
  56.  
  57.  
  58. void main(void)
  59.  
  60. {    double lb,ub,*initval,*matsol;
  61.     int nint,nret,neq,i,errcode;
  62.     double (**tabfunc)(double *);
  63.  
  64.     clrscr();
  65.     puts("Test program for function initcondsystem1");
  66.     puts("-----------------------------------------\n");
  67.  
  68.     neq = 2;
  69.     lb=3.0;
  70.     ub=4.0;
  71.  
  72.     if ((initval=farcalloc(neq,sizeof(double)))==NULL)
  73.     {    fputs("Not enough core", stderr);
  74.         exit(-1);
  75.     }
  76.  
  77.     tabfunc=farcalloc(2,sizeof( double (*)() ));
  78.  
  79.     if (tabfunc==NULL)
  80.     {    fputs("Not enough core", stderr);
  81.         exit(-1);
  82.     }
  83.     *tabfunc = *f1;
  84.     *(tabfunc+1) = *f2;
  85.  
  86.  
  87.     *initval     =  5.0;
  88.     *(initval+1) =  6.0;
  89.     nret=7;
  90.     nint=100;
  91.  
  92.     printf("Lower bound            : %+10.5lf\n",lb);
  93.     printf("Upper bound            : %+10.5lf\n",ub);
  94.  
  95.     for (i=0; i<neq; i++)
  96.         printf("x[%d] at t = %+lf     : %+10.5lf\n",i+1,lb,
  97.                             *(initval+i));
  98.     printf("Number of asked values : %3d\n",nret);
  99.     printf("Number of intervals    : %3d\n\n",nint);
  100.  
  101.     if ((matsol=farcalloc((neq+1)*nret, sizeof(double)))==NULL)
  102.     {    fputs("Not enough core", stderr);
  103.         exit(-1);
  104.     }
  105.  
  106.  
  107.     initcondsystem1(neq, lb, ub, initval,
  108.             nret, nint,
  109.             matsol,
  110.             &errcode, tabfunc);
  111.  
  112.     SYSMSG(errcode, stderr);
  113.  
  114.     results(neq, nret, matsol);
  115.  
  116.     farfree(initval);
  117.     farfree(matsol);
  118.     farfree(tabfunc);
  119.  
  120.  
  121. }
  122.  
  123.