声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2622|回复: 8

[分形与混沌] 求C语言版的lyapunov指数计算程序!

[复制链接]
发表于 2007-4-23 18:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
有没有高人有C语言版的lyapunov指数计算程序?
有的话送我一个,我的油箱:twh4108@126.com。多谢了!!!

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2007-4-24 14:10 | 显示全部楼层
请问你是计算一维还是高维系统的?
我可以给你、
 楼主| 发表于 2007-4-24 18:43 | 显示全部楼层
四维的,不管是几维的,如果你有的话就发给我一个,发到我信箱里吧。
多谢了!!!
发表于 2007-4-25 02:08 | 显示全部楼层
small data method

  1. /*
  2.   l1d2.c ... generates scaling data for calculating the largest
  3.              Lyapunov exponent and the correlation dimension

  4.              Copyright (c) 1999. Michael T. Rosenstein.

  5. This program is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free Software
  7. Foundation; either version 2 of the License, or (at your option) any later
  8. version.

  9. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11. PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  12. You should have received a copy of the GNU General Public License along with
  13. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  14. Place - Suite 330, Boston, MA 02111-1307, USA.

  15. You may contact the author by e-mail (mtr@cs.umass.edu) or postal mail
  16. (c/o Department of Computer Science, University of Massachusetts, 140 Governors
  17. Drive, Amherst, MA 01003-4610 USA).  For updates to this software, please visit
  18. PhysioNet (http://www.physionet.org/).

  19.          reference: M.T. Rosenstein, J.J. Collins, C.J. De Luca,
  20.                         A practical method for calculating largest
  21.                         Lyapunov exponents from small data sets,
  22.                         Physica D 65:117-134, 1993.

  23.              email contact: mtr@cs.umass.edu         
  24. */

  25. #include <ctype.h>
  26. #include <float.h>
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>

  31. #define IOTA            10e-15
  32. #define MAX_LN_R        12
  33. #define MIN_LN_R        -12
  34. #define N_LN_R            600

  35. typedef struct
  36. {
  37.   char  fileName[16];
  38.   long  startIndex, stopIndex;
  39.   int   seriesN, m, J, W, divergeT;
  40. } test;
  41.    
  42. double    **AllocateDMatrix(long nRows, long nCols);
  43. void    ComputeSlopes(void);
  44. void    FreeDMatrix(double **mat, long nRows);
  45. void    GenerateTemplateFile(void);
  46. long    GetData(char *fileName, int tsN, long start, long stop);
  47. void    LineFit(double *data, double n, double *m, double *b, double *rr);
  48. void    PercentDone(int percentDone);
  49. void    ProcessTest(int testN);
  50. void    ReadTestFile(char *fileName);
  51. void    SaveL1Results(char *fileRoot);
  52. void    SaveD2Results(char *fileRoot);

  53. int     gNTests, gMaxDivergeT;
  54. double  *gData, *gNDivergence;
  55. double  **gDivergence, **gCSum;
  56. test    *gTest;

  57. int    main(void)
  58. {
  59.   int   i;
  60.   char  str[256];
  61.    
  62.   printf("\n");
  63.   printf("*** L1D2: generates scaling information for L1 and D2 ***\n");
  64.   printf("          v1.0 Copyright (c) 1999 M.T. Rosenstein\n");
  65.   printf("                                  (mtr@cs.umass.edu)\n\n");
  66.   printf("          reference: M.T. Rosenstein, J.J. Collins, C.J. De Luca,\n");
  67.   printf("                     A practical method for calculating largest\n");
  68.   printf("                     Lyapunov exponents from small data sets,\n");
  69.   printf("                     Physica D 65:117-134, 1993.\n\n");
  70.    
  71.   GenerateTemplateFile();
  72.   
  73.   printf("Enter test file name: ");
  74.   scanf("%s", str);
  75.   ReadTestFile(str);
  76.    
  77.   printf("\nEnter output file root (no extension): ");
  78.   scanf("%s", str);

  79.   /* allocate the divergence and correlation sum arrays */
  80.   for(i=0; i<gNTests; i++)
  81.     if(gTest[i].divergeT > gMaxDivergeT)
  82.       gMaxDivergeT = 1+gTest[i].divergeT;
  83.   gNDivergence = (double *) calloc(gMaxDivergeT, sizeof(double));
  84.   gDivergence = AllocateDMatrix(gMaxDivergeT, 2*gNTests);
  85.   gCSum = AllocateDMatrix(N_LN_R, 2*gNTests);
  86.    
  87.   for(i=0; i<gNTests; i++)
  88.     ProcessTest(i);

  89.   ComputeSlopes();
  90.   printf("\n");
  91.   SaveL1Results(str);
  92.   SaveD2Results(str);
  93.    
  94.   printf("\nSuccess!\n");
  95.   return(0);
  96. }

  97. double **AllocateDMatrix(long nRows, long nCols)
  98. {
  99.   long   i;
  100.   double **mat;

  101.   /* allocate space for the row pointers */
  102.   mat = (double **) calloc(nRows, sizeof(double *));
  103.   if(mat == NULL)
  104.     {
  105.       printf("OUT OF MEMORY: AllocateDMatrix(%ld, %ld)\n\n", nRows, nCols);
  106.       exit(1);
  107.     };

  108.   /* allocate space for each row pointer */
  109.   for(i=0; i<nRows; i++)
  110.     mat[i] = (double *) calloc(nCols, sizeof(double));
  111.   if(mat[i-1] == NULL)
  112.     {
  113.       printf("OUT OF MEMORY: AllocateDMatrix(%ld, %ld)\n\n", nRows, nCols);
  114.       exit(1);
  115.     };

  116.   return(mat);
  117. }

  118. void   ComputeSlopes(void)
  119. {
  120.   int    i, i2, j;
  121.   double k, m, b, rr;
  122.   double *data;
  123.    
  124.   data = (double *) calloc(N_LN_R>gMaxDivergeT ? N_LN_R : gMaxDivergeT,
  125.                sizeof(double));
  126.   if(data == NULL)
  127.     {
  128.       printf("OUT OF MEMORY: ComputeSlopes\n\n");
  129.       exit(1);
  130.     };
  131.    
  132.   for(i=0; i<gNTests; i++)
  133.     {
  134.       i2 = i+gNTests;
  135.       
  136.       /*** work on correlation dimension first ***/
  137.       
  138.       k = (double) N_LN_R/(MAX_LN_R-MIN_LN_R);
  139.       
  140.       /* pack the array column into the local data array */
  141.       for(j=0; j<N_LN_R; j++)
  142.     data[j] = gCSum[j][i];        
  143.       /* compute the 7-point slopes */   
  144.       for(j=3; j<N_LN_R-3; j++)
  145.     {
  146.       LineFit(data+j-3, 7, &m, &b, &rr);
  147.       gCSum[j][i2] = k*m;
  148.     };
  149.       /* handle the edges */
  150.       LineFit(data, 5, &m, &b, &rr); gCSum[2][i2] = k*m;
  151.       LineFit(data+N_LN_R-5, 5, &m, &b, &rr); gCSum[N_LN_R-3][i2] = k*m;
  152.       LineFit(data, 3, &m, &b, &rr); gCSum[1][i2] = k*m;
  153.       LineFit(data+N_LN_R-3, 3, &m, &b, &rr); gCSum[N_LN_R-2][i2] = k*m;
  154.       gCSum[0][i2] = k*(data[1]-data[0]);
  155.       gCSum[N_LN_R-1][i2] = k*(data[N_LN_R-1]-data[N_LN_R-2]);
  156.       
  157.       /*** now work on divergence data ***/
  158.         
  159.       /* pack the array column into the local data array */
  160.       for(j=0; j<gMaxDivergeT; j++)
  161.     data[j] = gDivergence[j][i];        
  162.       /* compute the 7-point slopes */   
  163.       for(j=3; j<gMaxDivergeT-3; j++)
  164.     {
  165.       LineFit(data+j-3, 7, &m, &b, &rr);
  166.       gDivergence[j][i2] = m;
  167.     };
  168.       /* handle the edges */
  169.       LineFit(data, 5, &m, &b, &rr); gDivergence[2][i2] = m;
  170.       LineFit(data+gMaxDivergeT-5, 5, &m, &b, &rr);
  171.       gDivergence[gMaxDivergeT-3][i2] = m;
  172.       LineFit(data, 3, &m, &b, &rr);
  173.       gDivergence[1][i2] = m;
  174.       LineFit(data+gMaxDivergeT-3, 3, &m, &b, &rr);
  175.       gDivergence[gMaxDivergeT-2][i2] = m;
  176.       gDivergence[0][i2] = data[1]-data[0];
  177.       gDivergence[gMaxDivergeT-1][i2] = data[gMaxDivergeT-1]-
  178.     data[gMaxDivergeT-2];
  179.     };
  180. }

  181. void   FreeDMatrix(double **mat, long nRows)
  182. {
  183.   long   i;
  184.    
  185.   /* free space for each row pointer */
  186.   for(i=nRows-1; i>=0; i--)
  187.     free(mat[i]);
  188.   
  189.   /* free space for the row pointers */
  190.   free(mat);
  191. }

  192. void   GenerateTemplateFile(void)
  193. {
  194.   FILE   *outFile;

  195.   outFile = fopen("sample.l1d2", "w");

  196.   fprintf(outFile, "* Header info starts with an asterisk.\n*\n");
  197.   fprintf(outFile, "* Each line of the test file contains the name of a data file followed\n");
  198.   fprintf(outFile, "* by the parameters for the test:\n");
  199.   fprintf(outFile, "*   file_name series# startIndex stopIndex m J W divergeT\n*\n");
  200.   fprintf(outFile, "*      file_name  = name of the data file\n");
  201.   fprintf(outFile, "*      series#    = time series number to use for delay reconstruction\n");
  202.   fprintf(outFile, "*      startIndex = index of first data point to read (usually 1)\n");
  203.   fprintf(outFile, "*      stopIndex  = index of last data point to read\n");
  204.   fprintf(outFile, "*                      (enter 0 for maximum)\n");
  205.   fprintf(outFile, "*      m          = embedding dimension\n");
  206.   fprintf(outFile, "*      J          = delay in samples\n");
  207.   fprintf(outFile, "*      W          = window size for skipping temporally close nearest neighbors\n");
  208.   fprintf(outFile, "*      divergT    = total divergence time in samples\n");
  209.   fprintf(outFile, "*   example: lorenz.dat 1 1 0 5 7 100 300\n");
  210.    
  211.   fclose(outFile);
  212. }

  213. long   GetData(char *fileName, int tsN, long start, long stop)
  214. {
  215.   long   i, j, len;
  216.   long   nHead, nCols, nRows, nPts;
  217.   char   str[1024];
  218.   double dummy;
  219.   FILE   *inFile;

  220.   /* try to open the data file */
  221.   inFile = fopen(fileName, "r");
  222.   if(inFile == NULL)
  223.     {
  224.       printf("FILE ERROR: GetData(%s)\n\n", fileName);
  225.       exit(1);
  226.     };

  227.   /* skip the header */
  228.   nHead = 0;
  229.   fgets(str, 1024, inFile);
  230.   while(str[0]=='*')
  231.     {
  232.       nHead++;
  233.       fgets(str, 1024, inFile);
  234.     };
  235.         
  236.   /* figure out the number of columns */
  237.   len = strlen(str);
  238.   i = 0;
  239.   nCols = 0;
  240.   while(i<len)
  241.     {
  242.       if(!isspace(str[i]))
  243.     {
  244.       nCols++;
  245.       while(!isspace(str[i]) && i<len)
  246.         i++;
  247.       while(isspace(str[i]) && i<len)
  248.         i++;
  249.     }
  250.       else
  251.     i++;
  252.     };

  253.   /* figure out the number of rows; assume there's at least one */
  254.   nRows = 1;
  255.   while(fgets(str, 1024, inFile) != NULL)
  256.     nRows++;
  257.   
  258.   if(stop<start)
  259.     stop = nRows;
  260.   else if(stop>nRows)
  261.     stop = nRows;
  262.   if(start<1 || start>stop-3)
  263.     start = 1;
  264.   nPts = stop-start+1;
  265.   gData = calloc(nPts, sizeof(double));
  266.    
  267.   /* now read the time series data */
  268.   rewind(inFile);
  269.   for(i=0; i<nHead; i++)
  270.     fgets(str, 1024, inFile);
  271.   
  272.   for(i=1; i<start; i++)
  273.     for(j=0; j<nCols; j++)
  274.       fscanf(inFile, "%lf", &dummy);
  275.   for(i=0; i<nPts; i++)
  276.     {
  277.       for(j=0; j<tsN; j++)
  278.     fscanf(inFile, "%lf", &dummy);
  279.       gData[i] = dummy;
  280.       for(; j<nCols; j++)
  281.     fscanf(inFile, "%lf", &dummy);
  282.     };            
  283.   fclose(inFile);

  284.   return(nPts);
  285. }

  286. void   LineFit(double *data, double n, double *m, double *b, double *rr)
  287. {
  288.   int    i;
  289.   double sx, sy, sxy, sx2, sy2;
  290.   double x, y, k, mTemp, bTemp, rrTemp;

  291.   sx = sy = sxy = sx2 = sy2 = 0;
  292.   for(i=0; i<n; i++)
  293.     {
  294.       x = i;
  295.       y = data[i];
  296.       sx += x; sy += y;
  297.       sx2 += x*x; sy2 += y*y;
  298.       sxy += x*y;
  299.     };
  300.   k = n*sx2-sx*sx;
  301.   mTemp = (n*sxy-sx*sy)/k;
  302.   bTemp = (sx2*sy-sx*sxy)/k;
  303.   k = sy*sy/n;
  304.   if(k==sy2)
  305.     rrTemp = 1.0;
  306.   else
  307.     {
  308.       rrTemp = (bTemp*sy+mTemp*sxy-k)/(sy2-k);
  309.       rrTemp = 1.0 - (1.0-rrTemp)*(n-1.0)/(n-2.0);
  310.     };
  311.   *m = mTemp;
  312.   *b = bTemp;
  313.   *rr = rrTemp;
  314. }

  315. void   PercentDone(int percentDone)
  316. {
  317.   static last=100;
  318.   
  319.   if(percentDone<last)
  320.     {
  321.       last = 0;
  322.       printf("0");
  323.       fflush(stdout);
  324.     }
  325.   else if(percentDone>last && percentDone%2==0)
  326.     {
  327.       last = percentDone;
  328.       if(percentDone%10==0)
  329.     printf("%d", percentDone/10);
  330.       else
  331.     printf(".");
  332.       fflush(stdout);
  333.     };
  334. }

  335. void   ProcessTest(int testN)
  336. {
  337.   long   m, J, W, divergeT, neighborIndex, maxIndex;
  338.   long   i, j, k, T, CSumIndex, percentDone;
  339.   long   nPts, nCompletedPairs=0, nVectors;
  340.   char   *isNeighbor;
  341.   double distance, d;
  342.   double k1, k2, temp, kNorm;

  343.   printf("\nProcessing test %d of %d:  ", testN+1, gNTests);
  344.   fflush(stdout);
  345.    
  346.   m = gTest[testN].m;
  347.   J = gTest[testN].J;
  348.   W = gTest[testN].W;
  349.   divergeT = gTest[testN].divergeT;
  350.   nPts = GetData(gTest[testN].fileName, gTest[testN].seriesN,
  351.          gTest[testN].startIndex, gTest[testN].stopIndex);
  352.    
  353.   k1 = (double) N_LN_R/(MAX_LN_R-MIN_LN_R);
  354.   k1 *= 0.5; /* accounts for the SQUARED distances later on */
  355.   k2 = N_LN_R/2;

  356.   nVectors = nPts-J*(m-1);
  357.    
  358.   isNeighbor = (char *) calloc(nVectors, sizeof(char));
  359.   if(isNeighbor==NULL)
  360.     {
  361.       printf("\nOUT OF MEMORY: ProcessTest\n\n");
  362.       exit(1);
  363.     };   
  364.    
  365.   /* clear the divergence arrays */
  366.   for(i=0; i<gMaxDivergeT; i++)
  367.     gNDivergence[i] = gDivergence[i][testN] = 0;

  368.   /* loop through vectors */
  369.   i = 0;
  370.   while(i<nVectors)
  371.     {
  372.       percentDone = 100.0*nCompletedPairs/nVectors*2+0.5;
  373.       percentDone = 100.0*i/nVectors+0.5;
  374.       PercentDone(percentDone);
  375.       
  376.       if(!isNeighbor[i])
  377.     {
  378.       distance = 10e10;
  379.       
  380.       /* find the nearest neighbor for the vector at i */
  381.       /* ignore temporally close neighbors using W */
  382.       if(i>W)
  383.         for(j=0; j<i-W; j++)
  384.           {
  385.         /* calculate distance squared */
  386.         d=0;
  387.         for(k=0; k<m; k++)
  388.           {
  389.             T = k*J;
  390.             temp = gData[i+T]-gData[j+T];
  391.             temp *= temp;
  392.             d += temp;
  393.           };
  394.         d += IOTA;
  395.    
  396.         /* map the squared distance to array position */
  397.         CSumIndex = k1*log(d)+k2;
  398.         if(CSumIndex<0)
  399.           CSumIndex = 0;
  400.         if(CSumIndex>=N_LN_R)
  401.           CSumIndex = N_LN_R-1;
  402.         
  403.         /* increment the correlation sum array */
  404.         gCSum[CSumIndex][testN]++;

  405.         /* now compare to current nearest neighbor */
  406.         /* use IOTA above to ignore nbrs that are too close */
  407.         if(d<distance)
  408.           {
  409.             distance=d;
  410.             neighborIndex=j;
  411.           };
  412.           };
  413.       if(i<nVectors-W)
  414.         for(j=i+W; j<nVectors; j++)
  415.           {
  416.         d=0;
  417.         for(k=0; k<m; k++)
  418.           {
  419.             T = k*J;
  420.             temp = gData[i+T]-gData[j+T];
  421.             temp *= temp;
  422.             d += temp;
  423.           };
  424.         d += IOTA;

  425.         CSumIndex = k1*log(d)+k2;
  426.         if(CSumIndex<0)
  427.           CSumIndex = 0;
  428.         if(CSumIndex>=N_LN_R)
  429.           CSumIndex = N_LN_R-1;

  430.         gCSum[CSumIndex][testN]++;
  431.         
  432.         if(d<distance)
  433.           {
  434.             distance=d;
  435.             neighborIndex=j;
  436.           };
  437.           };
  438.       isNeighbor[neighborIndex] = 1;

  439.       /* track divergence */
  440.       for(j=0; j<=divergeT; j++)
  441.         {
  442.           maxIndex = nPts-m*J-j-1;
  443.           if(i<maxIndex && neighborIndex<maxIndex)
  444.         {
  445.           d=0;
  446.           for(k=0; k<m; k++)
  447.             {
  448.               T = k*J+j;
  449.               temp = gData[i+T]-gData[neighborIndex+T];
  450.               temp *= temp;
  451.               d += temp;
  452.             };
  453.           d += IOTA;
  454.           gNDivergence[j]++;
  455.           temp = 0.5*log(d);
  456.           gDivergence[j][testN] += temp;
  457.         };
  458.         };
  459.       nCompletedPairs++;
  460.     };
  461.       i++;
  462.     };

  463.   /* integrate the correlation sum array to get the correlation sum curve */
  464.   for(i=1; i<N_LN_R; i++)
  465.     gCSum[i][testN] += gCSum[i-1][testN];

  466.   /* next normalize values */
  467.   kNorm = 1.0/gCSum[N_LN_R-1][testN];
  468.   for(i=0; i<N_LN_R; i++)
  469.     gCSum[i][testN] *= kNorm;

  470.   /* now take natural log of the values */
  471.   for(i=0; i<N_LN_R; i++)
  472.     {
  473.       temp = gCSum[i][testN];
  474.       if( (temp<0.000045) || (temp>0.990050) )
  475.     gCSum[i][testN] = 0;
  476.       else
  477.     gCSum[i][testN] = log(temp);
  478.     };

  479.   /* now take care of Lyapunovv average */
  480.   for(i=0; i<=divergeT; i++)
  481.     if(gNDivergence[i]>0)
  482.       gDivergence[i][testN] /= gNDivergence[i];

  483.   free(isNeighbor);
  484.   free(gData);
  485. }

  486. void   ReadTestFile(char *fileName)
  487. {
  488.   int    i;
  489.   int    nHead, nRows;
  490.   char   str[1024];
  491.   FILE   *inFile;

  492.   printf("\nReading Test File...\n");

  493.   /* try to open the data file */
  494.   inFile = fopen(fileName, "r");
  495.   if(inFile == NULL)
  496.     {
  497.       printf("FILE ERROR: ReadTestFile(%s)\n\n", fileName);
  498.       exit(1);
  499.     };

  500.   /* skip the header */
  501.   nHead = 0;
  502.   fgets(str, 1024, inFile);
  503.   while(str[0]=='*')
  504.     {
  505.       nHead++;
  506.       fgets(str, 1024, inFile);
  507.     };

  508.   /* figure out the number of rows; assume there's at least one */
  509.   nRows = 1;
  510.   while(fgets(str, 1024, inFile) != NULL && !isspace(str[0]))
  511.     nRows++;
  512.   gNTests = nRows;
  513.       
  514.   /* allocate the test array */
  515.   gTest = (test *) calloc(gNTests, sizeof(test));
  516.   if(gTest == NULL)
  517.     {
  518.       printf("OUT OF MEMORY: ReadTestFile(%d)\n\n", gNTests);
  519.       exit(1);
  520.     };
  521.       
  522.   printf("detected %d %s\n", gNTests, gNTests==1 ? "test" : "tests");
  523.    
  524.   /* rewind the file and skip the header */
  525.   rewind(inFile);
  526.   for(i=0; i<nHead; i++)
  527.     fgets(str, 1024, inFile);
  528.   
  529.   for(i=0; i<gNTests; i++)
  530.     fscanf(inFile, "%s %d %ld %ld %d %d %d %d\n",
  531.        gTest[i].fileName, &gTest[i].seriesN, &gTest[i].startIndex,
  532.        &gTest[i].stopIndex, &gTest[i].m, &gTest[i].J, &gTest[i].W,
  533.        &gTest[i].divergeT);

  534.   fclose(inFile);
  535. }

  536. void   SaveD2Results(char *fileRoot)
  537. {
  538.   int    i, i1, i2, testN, keepGoing;
  539.   char   str[256];
  540.   double k1, k2;
  541.   FILE   *outFile;
  542.    
  543.   printf("\nSaving data for correlation dimension...\n");

  544.   sprintf(str, "%s.d2", fileRoot);
  545.   outFile = fopen(str, "w");
  546.    
  547.   k1 = (double) (MAX_LN_R-MIN_LN_R)/N_LN_R;
  548.   k2 = MIN_LN_R;

  549.   /* don't save rows of just zeros */
  550.   keepGoing = 1;
  551.   i1 = 0;
  552.   while(keepGoing)
  553.     {
  554.       for(testN=0; testN<gNTests; testN++)
  555.     if(gCSum[i1][testN]!=0)
  556.       {
  557.         keepGoing = 0;
  558.         break;
  559.       };
  560.       i1 += keepGoing;
  561.     };
  562.   i1--;
  563.   if(i1<0 || i1>=N_LN_R)
  564.     i1 = 0;
  565.   keepGoing = 1;
  566.   i2 = N_LN_R-1;
  567.   while(keepGoing)
  568.     {
  569.       for(testN=0; testN<gNTests; testN++)
  570.     if(gCSum[i2][testN]!=0)
  571.       {
  572.         keepGoing = 0;
  573.         break;
  574.       };
  575.       i2 -= keepGoing;
  576.     };
  577.   i2++;
  578.   if(i2<0 || i2>=N_LN_R)
  579.     i2 = N_LN_R-1;

  580.   /* write the data */
  581.   for(i=i1; i<i2+1; i++)
  582.     {
  583.       fprintf(outFile, "%lf\t", k1*i+k2);
  584.       for(testN=0; testN<gNTests; testN++)
  585.     fprintf(outFile, "%lf\t", gCSum[i][testN]);
  586.         
  587.       /* write slope data */
  588.       fprintf(outFile, "%lf\t", k1*i+k2);
  589.       for(; testN<2*gNTests-1; testN++)
  590.     fprintf(outFile, "%lf\t", gCSum[i][testN]);
  591.       fprintf(outFile, "%lf\n", gCSum[i][testN]);
  592.     };

  593.   fclose(outFile);
  594. }

  595. void    SaveL1Results(char *fileRoot)
  596. {
  597.   int   i, testN;
  598.   char  str[256];
  599.   FILE  *outFile;
  600.    
  601.   printf("\nSaving data for largest Lyapunov exponent...\n");

  602.   sprintf(str, "%s.l1", fileRoot);
  603.   outFile = fopen(str, "w");
  604.    
  605.   for(i=0; i<gMaxDivergeT; i++)
  606.     {
  607.       fprintf(outFile, "%d\t", i);
  608.       for(testN=0; testN<gNTests; testN++)
  609.     if(i<=gTest[testN].divergeT)
  610.       fprintf(outFile, "%lf\t", gDivergence[i][testN]);
  611.     else
  612.       fprintf(outFile, "\t");
  613.       
  614.       /* write slope data */
  615.       fprintf(outFile, "%d\t", i);
  616.       for(; testN<2*gNTests-1; testN++)
  617.     if(i<=gTest[testN-gNTests].divergeT)
  618.       fprintf(outFile, "%lf\t", gDivergence[i][testN]);
  619.     else
  620.       fprintf(outFile, "\t");
  621.       if(i<=gTest[testN-gNTests].divergeT)
  622.     fprintf(outFile, "%lf\n", gDivergence[i][testN]);
  623.       else
  624.     fprintf(outFile, "\n");
  625.     };

  626.   fclose(outFile);
  627. }
复制代码

评分

1

查看全部评分

发表于 2007-4-25 18:41 | 显示全部楼层
double CHenon::MaxLypunov()
{
        double z0[2],z[2],x[2],y[2];//
        double d0=0.0001,lnd0;
        double d,sum_ln_di=0.0;
        for(int k=0;k<2;k++)
        {
                z[k]=z0[k]=xini[k]+d0;
                x[k]=xini[k];
        }
        d0=dis(x,z);
        lnd0=log(d0);
        for(int i=0;i<MAX;i++)
        {
                fun(x,y);
                x[0]=y[0];x[1]=y[1];
                fun(z,y);
                z[0]=y[0];z[1]=y[1];
                d=dis(x,z);
                sum_ln_di+=log(d);
                for(int j=0;j<2;j++)
                {
                        z[j]=x[j]+d0*(z[j]-x[j])/d;
                }
        }
        d=sum_ln_di/MAX;
        d=d-lnd0;
        return d;
}
二位henon映射的计算最大李指数的程序

评分

1

查看全部评分

发表于 2007-4-26 00:57 | 显示全部楼层
 楼主| 发表于 2007-4-26 10:05 | 显示全部楼层
多谢大家提供的程序!!!
谢谢!!!:@) :@)
发表于 2007-5-23 17:01 | 显示全部楼层

求助!

有人会编wolf方法计算lyapunov指数的C语言版的程序吗 ?多维的!帮忙发到我邮箱里吧[email=!yww537@163.com]!yww537@163.com[/email] 多谢!
发表于 2007-5-24 07:20 | 显示全部楼层
原帖由 yww3973537 于 2007-5-23 17:01 发表
有人会编wolf方法计算lyapunov指数的C语言版的程序吗 ?多维的!帮忙发到我邮箱里吧yww537@163.com]!yww537@163.com 多谢!


还发到信箱,受不了,估计此人90%就此消失
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-25 05:11 , Processed in 0.107746 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表