wronkl.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Wronksian test for Bessel functions. */
  2. long double jnl (), ynl (), floorl ();
  3. #define PI 3.14159265358979323846L
  4. long double y, Jn, Jnp1, Jmn, Jmnp1, Yn, Ynp1;
  5. long double w1, w2, err1, max1, err2, max2;
  6. void wronk ();
  7. main ()
  8. {
  9. long double x, delta;
  10. int n, i, j;
  11. max1 = 0.0L;
  12. max2 = 0.0L;
  13. delta = 0.6 / PI;
  14. for (n = -30; n <= 30; n++)
  15. {
  16. x = -30.0;
  17. while (x < 30.0)
  18. {
  19. wronk (n, x);
  20. x += delta;
  21. }
  22. delta += .00123456;
  23. }
  24. }
  25. void
  26. wronk (n, x)
  27. int n;
  28. long double x;
  29. {
  30. Jnp1 = jnl (n + 1, x);
  31. Jmn = jnl (-n, x);
  32. Jn = jnl (n, x);
  33. Jmnp1 = jnl (-(n + 1), x);
  34. /* This should be trivially zero. */
  35. err1 = Jnp1 * Jmn + Jn * Jmnp1;
  36. if (err1 < 0.0)
  37. err1 = -err1;
  38. if (err1 > max1)
  39. {
  40. max1 = err1;
  41. printf ("1 %3d %.5Le %.3Le\n", n, x, max1);
  42. }
  43. if (x < 0.0)
  44. {
  45. x = -x;
  46. Jn = jnl (n, x);
  47. Jnp1 = jnl (n + 1, x);
  48. }
  49. Yn = ynl (n, x);
  50. Ynp1 = ynl (n + 1, x);
  51. /* The Wronksian. */
  52. w1 = Jnp1 * Yn - Jn * Ynp1;
  53. /* What the Wronksian should be. */
  54. w2 = 2.0 / (PI * x);
  55. err2 = w1 - w2;
  56. if (err2 > max2)
  57. {
  58. max2 = err2;
  59. printf ("2 %3d %.5Le %.3Le\n", n, x, max2);
  60. }
  61. }