func2d.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*!
  2. * \file func2d.c
  3. *
  4. * \author
  5. * Lubos Mitas (original program and various modifications)
  6. *
  7. * \author
  8. * H. Mitasova,
  9. * I. Kosinovsky, D. Gerdes,
  10. * D. McCauley
  11. * (GRASS4.1 version of the program and GRASS4.2 modifications)
  12. *
  13. * \author
  14. * L. Mitas ,
  15. * H. Mitasova ,
  16. * I. Kosinovsky,
  17. * D.Gerdes
  18. * D. McCauley (1993, 1995)
  19. *
  20. * \author modified by McCauley in August 1995
  21. * \author modified by Mitasova in August 1995, Nov. 1996
  22. *
  23. * \copyright
  24. * (C) 1993-1999 by Lubos Mitas and the GRASS Development Team
  25. *
  26. * \copyright
  27. * This program is free software under the
  28. * GNU General Public License (>=v2).
  29. * Read the file COPYING that comes with GRASS
  30. * for details.
  31. */
  32. #include <stdio.h>
  33. #include <math.h>
  34. #include <grass/gis.h>
  35. #include <grass/interpf.h>
  36. /* parameter description from DESCRIPTION.INTERP */
  37. /*!
  38. * Radial basis function
  39. *
  40. * Radial basis function - completely regularized spline with tension (d=2)
  41. *
  42. */
  43. double IL_crst(double r, /**< distance squared */
  44. double fi /**< tension */
  45. )
  46. {
  47. double rfsta2 = fi * fi * r / 4.;
  48. static double c[4] = { 8.5733287401, 18.0590169730, 8.6347608925,
  49. 0.2677737343
  50. };
  51. static double b[4] = { 9.5733223454, 25.6329561486, 21.0996530827,
  52. 3.9584969228
  53. };
  54. double ce = 0.57721566;
  55. static double u[10] = { 1.e+00, -.25e+00,
  56. .055555555555556e+00, -.010416666666667e+00, /*fixed bug 415.. repl. by 416.. */
  57. .166666666666667e-02, -2.31481481481482e-04,
  58. 2.83446712018141e-05, -3.10019841269841e-06,
  59. 3.06192435822065e-07, -2.75573192239859e-08
  60. };
  61. double x = rfsta2;
  62. double res;
  63. double e1, ea, eb;
  64. if (x < 1.e+00) {
  65. res = x * (u[0] + x * (u[1] + x * (u[2] + x * (u[3] + x * (u[4] + x *
  66. (u[5] +
  67. x *
  68. (u[6] +
  69. x *
  70. (u[7] +
  71. x *
  72. (u[8] +
  73. x *
  74. u
  75. [9])))))))));
  76. return (res);
  77. }
  78. if (x > 25.e+00)
  79. e1 = 0.00;
  80. else {
  81. ea = c[3] + x * (c[2] + x * (c[1] + x * (c[0] + x)));
  82. eb = b[3] + x * (b[2] + x * (b[1] + x * (b[0] + x)));
  83. e1 = (ea / eb) / (x * exp(x));
  84. }
  85. res = e1 + ce + log(x);
  86. return (res);
  87. }
  88. /*!
  89. * Function for calculating derivatives (d=2)
  90. *
  91. * Derivatives of radial basis function - regularized spline with tension(d=2)
  92. */
  93. int IL_crstg(double r, /**< distance squared */
  94. double fi, /**< tension */
  95. double *gd1, /**< G1(r) */
  96. double *gd2 /**< G2(r) */
  97. )
  98. {
  99. double r2 = r;
  100. double rfsta2 = fi * fi * r / 4.;
  101. double x, exm, oneme, hold;
  102. double fsta2 = fi * fi / 2.;
  103. x = rfsta2;
  104. if (x < 0.001) {
  105. *gd1 = 1. - x / 2. + x * x / 6. - x * x * x / 24.;
  106. *gd2 = fsta2 * (-.5 + x / 3. - x * x / 8. + x * x * x / 30.);
  107. }
  108. else {
  109. if (x < 35.e+00) {
  110. exm = exp(-x);
  111. oneme = 1. - exm;
  112. *gd1 = oneme / x;
  113. hold = x * exm - oneme;
  114. *gd2 = (hold + hold) / (r2 * x);
  115. }
  116. else {
  117. *gd1 = 1. / x;
  118. *gd2 = -2. / (x * r2);
  119. }
  120. }
  121. return 1;
  122. }