Home > wafo > multidim > ratio.m

ratio

PURPOSE ^

compute ratio of hyperbolic functions

SYNOPSIS ^

[r,r2]=ratio(a,b,sa,sb);

DESCRIPTION ^

 RATIO compute ratio of hyperbolic functions 
       to allow extreme variations of arguments. 
  
  CALL: r=ratio(a,b,sa,sb); 
  
        r = f(a,sa)./f(b,sb), ratio vector hyperbolic functions of same 
                 size as a and b 
      a,b = arguments vectors of the same size 
    sa,sb = defines the hyperbolic function used, i.e., 
            f(x,1)=cosh(x), f(x,-1)=sinh(x) 
  
  Examples: 
  ratio(2,1,1,1)   % gives r=cosh(2)/cosh(1) 
  ratio(2,1,1,-1)  % gives r=cosh(2)/sinh(1) 
  ratio(2,1,-1,1)  % gives r=sinh(2)/cosh(1) 
  ratio(2,1,-1,-1) % gives r=sinh(2)/sinh(1) 
  
  See also  tran

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [r,r2]=ratio(a,b,sa,sb); 
002 %RATIO compute ratio of hyperbolic functions 
003 %      to allow extreme variations of arguments. 
004 % 
005 % CALL: r=ratio(a,b,sa,sb); 
006 % 
007 %       r = f(a,sa)./f(b,sb), ratio vector hyperbolic functions of same 
008 %                size as a and b 
009 %     a,b = arguments vectors of the same size 
010 %   sa,sb = defines the hyperbolic function used, i.e., 
011 %           f(x,1)=cosh(x), f(x,-1)=sinh(x) 
012 % 
013 % Examples: 
014 % ratio(2,1,1,1)   % gives r=cosh(2)/cosh(1) 
015 % ratio(2,1,1,-1)  % gives r=cosh(2)/sinh(1) 
016 % ratio(2,1,-1,1)  % gives r=sinh(2)/cosh(1) 
017 % ratio(2,1,-1,-1) % gives r=sinh(2)/sinh(1) 
018 % 
019 % See also  tran 
020  
021 % Tested on: matlab 5.2 
022 % history 
023 % revised pab dec2003  
024 % commented out old call   
025 % added todo comment   
026 % revised pab 09.10.2002 
027 % -fixed bug: replaced * with .* thanks to Françoise GIRARD  
028 % -added more checks when a==b and when a<0 or b<0 => made it more robust 
029 % revised pab 07.11.2001 
030 % -added comnsize + see also line 
031 % -Fixed a bug: ratio(0,0,-1,-1) gave NaN but should return 1 
032 % revised pab 11.01.2000 
033 % - added sign(s1), sign(s2) to ensure correct calculation 
034 % - updated documentation 
035 % - fixed a bug in expression. 
036 % by L. Borgman 
037  
038 % TODO % Does not always handle division by zero correctly 
039  
040 [ec, a,b,sa,sb]=comnsize(a,b,sign(sa),sign(sb)); 
041 if ec~=0, 
042    error('a,b,sa and sb must be of common size or scalar!') 
043 end     
044 r = zeros(size(a)); 
045  
046 sc = (a==b); 
047   
048 k = find(sc); 
049 if any(k) 
050    r(k) = 1; 
051    d = 0.5*(sb(k)-sa(k)); 
052    k0 = find(d~=0); 
053    if any(k0) 
054      k00 = k(k0);  
055      r(k00) = tanh(a(k00)).^d(k0); 
056    end     
057 end     
058  
059  
060 k1 = find(~sc); 
061 if any(k1), 
062    ak = a(k1); 
063    bk = b(k1); 
064    sak = sa(k1); 
065    sbk = sb(k1); 
066    signRatio = ones(size(k1)); 
067    ka = find(sak.*ak<0); 
068    if any(ka) 
069      signRatio(ka) =  sak(ka); 
070   end     
071   kb = find(sbk.*bk<0); 
072   if any(kb) 
073      signRatio(kb) =  signRatio(kb).*sbk(kb); 
074   end     
075  
076   %signRatio = (2*(0<=ak)-1).*(2*(0<=bk)-1).*sak.*sbk 
077    bk = abs(bk); 
078    ak = abs(ak); 
079    warning off    % fix to avoid warning messages about division by zero.     
080    r(k1)=signRatio.*exp(ak-bk).*((sak+exp(-2*ak))./(sbk+exp(-2*bk))); 
081    warning on 
082  end     
083  
084 return 
085  
086 % Old call 
087 %r=exp(a-b).*(1+sign(sa)*exp(-2*a))./(1+sign(sb)*exp(-2*b)); 
088  
089 return 
090   
091

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003