home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / ELFUN.DI$ / COSH.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.1 KB  |  41 lines

  1. function y = cosh(xin)
  2. %COSH    Hyperbolic cosine.
  3. %    COSH(X) is the hyperbolic cosine of the elements of X.
  4.  
  5. %    J.M. Hammond, 6-17-92
  6. %    Copyright (c) 1984-93 by the MathWorks, Inc.
  7.  
  8. %       21 Oct 92 (jmh) -- fixed for matrix inputs
  9.  
  10. % Complex argument
  11. if any(any(imag(xin) ~= 0))
  12.     x = real(xin);
  13.     y = imag(xin);
  14.     y = cosh(x).*cos(y) + i*sinh(x).*sin(y);
  15.  
  16. % Real argument
  17. else
  18.     % Reference: W. J. Cody and W. Waite, "Software Manual
  19.     % for the Elementary Functions", 1980, chapter 12.
  20.  
  21.     lnv  = 0.6931610107421875;     % v is close to 2, log(v) is exact
  22.     xbar = 7.083964185322641e+02;  % log(1/realmin)
  23.     vf   = 0.138302778796019e-04;  % v/2-1, where v is as above
  24.  
  25.     x = abs(xin);
  26.     y = zeros(size(x));
  27.  
  28.     % Use regular formula
  29.     k = (x <= xbar) | isnan(x);
  30.     if any(any(k))            % 21 Oct 92 (jmh)
  31.         y(k) = (exp(x(k)) + exp(-x(k)))/2;
  32.     end
  33.  
  34.     % Dodge overflow problem for answers close to realmax
  35.     k = (xbar < x);
  36.     if any(any(k))            % 21 Oct 92 (jmh)
  37.         x(k) = x(k) - lnv;
  38.         y(k) = exp(x(k)) + vf .* exp(x(k));
  39.     end
  40. end
  41.