home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPECFUN.DI$ / BESSEL.M next >
Encoding:
Text File  |  1993-03-07  |  1.6 KB  |  60 lines

  1. function b = bessel(alpha,xx)
  2. %BESSEL    Bessel functions of various kinds.
  3. %    The suite of M-files for Bessel functions has been modified and
  4. %    extended since the reference manuals for MATLAB 3.5 and 4.0 were
  5. %    printed.  The underlying algorithms have been substantially
  6. %    improved.  There are now four primary functions for real X.
  7. %
  8. %        BESSELJ(ALPHA,X)  Bessel functions of the first kind,
  9. %        BESSELY(ALPHA,X)  Bessel functions of the second kind,
  10. %        BESSELI(ALPHA,X)  Modified Bessel functions of the first kind,
  11. %        BESSELK(ALPHA,X)  Modified Bessel functions of the second kind.
  12. %
  13. %    An old function, BESSELA(ALPHA,X), accepts complex X, but may
  14. %    produce inaccurate results for large ALPHA or large X.
  15. %
  16. %    This M-file, BESSEL(ALPHA,X), calls BESSELJ(ALPHA,X) if X is real,
  17. %    BESSELI(ALPHA,X) if X is imaginary, and BESSELA(ALPHA,X) if X
  18. %    is complex.  The auxilliary routine BESSELN is no longer used.
  19. %    BESSELH has been superceded by BESSELY.
  20.  
  21. %    C. Moler, 10/12/92.
  22. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  23.  
  24. resize = (length(alpha) == 1);
  25. if resize, resize = size(xx); end
  26. xx = xx(:);
  27. b = zeros(length(xx),length(alpha));
  28.  
  29. % Real x.
  30.  
  31. v = find(imag(xx(:)) == 0);
  32. if any(v)
  33.    b(v,:) = besselj(alpha,xx(v));
  34. end
  35.  
  36.  
  37. % Imaginary x.
  38.  
  39. v = find(real(xx(:)) == 0);
  40. if any(v)
  41.    if alpha == fix(alpha)
  42.       sig = [1 i -1 -i];
  43.       sig = sig(rem(alpha,4)+1);
  44.    else
  45.       sig = i^(alpha);
  46.    end
  47.    b(v,:) = sig*besseli(alpha,imag(xx(v)));
  48. end
  49.  
  50. % Complex x.
  51.  
  52. v = find((real(xx(:)) ~= 0) & (imag(xx(:)) ~= 0));
  53. if any(v)
  54.    b(v,:) = bessela(alpha,xx(v));
  55. end
  56.  
  57. if resize
  58.    b = reshape(b,resize(1),resize(2));
  59. end
  60.