<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hello,<br>
      <br>
      Le 14/08/2014 15:12, Pierre Vuillemin a écrit :<br>
    </div>
    <blockquote cite="mid:1408021933.2167.17.camel@Pelisse.lan"
      type="cite">
      <pre wrap="">Hello,

my question concerns the practical implementation of the complex inverse
tangent function atan(z) in Scilab.

In the source code of Scilab, the file "watan.f" (in the elementary
functions) seems to compute this function as

atan(z) = i/2 log((i+z)/(i-z)),

where i^2=-1.

Yet, when comparing the result given by atan(z) and %i/2*log((%i+z)/(%
i-z)) in Scilab, they are different for every point on the imaginary
axis excepted in the unit circle. For instance,

z = 2*%i
disp([atan(z),%i/2*log((%i+z)/(%i-z))])

-> 1.5707963 + 0.5493061i  - 1.5707963 + 0.5493061i</pre>
    </blockquote>
    With Scilab 5.5.0 on Windows 7 x64:<br>
    <font face="Courier New, Courier, monospace">-->z = 2*%i<br>
       z  =<br>
          2.i  <br>
      -->disp([atan(z),%i/2*log((%i+z)/(%i-z))])<br>
       <br>
          1.5707963 + 0.5493061i    1.5707963 + 0.5493061i  </font><br>
    <br>
    This is a strange result for the log expression, since we could
    expect -1.57.. rather than 1.57...<br>
    Indeed, with z = 2.i, we have: (i+z)/(i-z) = 3i/ -i = -3 = 3.i^2
    => ln(3.i^2) = ln(3) + 2 ln(i)<br>
    with i = exp(i.pi/2), so : .. = ln(3) + 2.i.pi/2 = ln(3) + i.pi<br>
    Hence: i/2 * ln((i+z)/(i-z)) = i.ln(3)/2 - pi/2 : the real part is
    < 0.<br>
    If there is an issue, it could be with  log() rather than with
    atan().<br>
    ...<br>
    <br>
    <blockquote cite="mid:1408021933.2167.17.camel@Pelisse.lan"
      type="cite">
      <pre wrap="">I would like to know where does the difference comes from and if
'watan.f' is really the file that computes atan.

The values obtained with the function atan(z) seem to coincide with
another definition of atan(z) :

atan(z) = 1/(2i) [log(1+iz)-log(1-iz)]

which is used by Mathematica and the function 'catan' in linux.</pre>
    </blockquote>
    <pre wrap="">1/(2i) [log(1+iz)-log(1-iz)] 
  = -i/2 log((1+iz)/(1-iz)) 
  = -i/2 log(i(1+iz) / i(1-iz)) 
  = -i/2 log((i-z)/(i+z)) 
  =  i/2 log((i+z)/(i-z))
So, both forms that you mention and that you compare to Scilab result are equivalent.

HTH
Samuel

</pre>
  </body>
</html>