Re: [Scilab-users] About the complex inverse tangent function
Le vendredi 15 août 2014 à 11:28 +0200, Samuel Gougeon a écrit : > Hello Pierre, > > Le 15/08/2014 10:52, Pierre Vuillemin a écrit : > > Le jeudi 14 août 2014 à 19:46 +0200, Samuel Gougeon a écrit : > >> With Scilab 5.5.0 on Windows 7 x64: > >> -->z = 2*%i > >> z = > >> 2.i > >> -->disp([atan(z),%i/2*log((%i+z)/(%i-z))]) > >> > >> 1.5707963 + 0.5493061i1.5707963 + 0.5493061i > > I am on a 64-bit linux environment (Debian Jessie, Scilab 5.5.0), the > > result would be OS-dependent? > It is possible. Some packages or/and some single functions -- including > maths ones -- depend on the OS. > > The relation > > > > log(ab) = log(a) + log(b) > > > > only stands for the multi-valued logarithm function (or modulo pi). With > > the principal value of the log, defined as > > > > log(z) = ln(|z|) + i * arg(z) > > > > where -pi Is this interval conventionnaly standard for the principal value, rather > than -pi <= arg(z) < pi ? I have considered the same definitions as in (Section 4.1.2) Handbook of Mathematical Functions: With Formulas, Graphs, and Mathematical tables Milton Abramowitz,Irene A. Stegun or Branch Cuts for Complex Elementary Functions or Much Ado About Nothing's Sign Bit W. Kahan The same domain for the principal value is used by Wolfram, http://mathworld.wolfram.com/ComplexArgument.html by Matlab, http://www.mathworks.fr/fr/help/symbolic/mupad_ref/arg.html and seems to be used by Scilab as well https://help.scilab.org/docs/5.5.0/en_US/atan.html > > this is not true as soon as -pi > pi. In particular, it is not true on the branch cut (- inf, 0]. > > For instance, > > > > log(-1) = j pi > > > > log(-1)+log(-1) = 2j pi != log(1) = 0 > It is, modulo 2.pi : i.2.pi [2.pi] ~ i.0 = 0 The relation is also violated for any complex in the upper left half plane, thus the modulo operation is not very well suited here. Something less ambiguous seems to use the "unwinding number" : The unwinding Number (R.M. Corless and D.J. Jeffrey) : http://www.apmaths.uwo.ca/~djeffrey/Offprints/editors.pdf which basically consists in adding 2Ki pi whenever required to make standard relations work everywhere in the complex plane. > > This is merely a problem of convention in the definitions, but this > > leads to differences in the value of the atan on its branch cuts. > Indeed. Both results that you get from atan and log on Linux are > correct, and equivalent. > Results from win7 are equal and agree with the standard interval (-pi, pi]. > > Samuel > I perfectly understand that each definition is equivalent "up to 2K i pi", yet from a numerical point of view, it seems to me that they cannot be considered as equivalent. But the thing that really intrigues me is why the built-in function of atan in Scilab does not lead to the same result (in the exact sense) as the formulation in the commentary of the code 'watan.f'. I will try to determine what is really called by Scilab. The OS atan would correspond. Thank you for your answers. :) Pierre > ___ > users mailing list > users@lists.scilab.org > http://lists.scilab.org/mailman/listinfo/users ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] About the complex inverse tangent function
Hello Pierre, Le 15/08/2014 10:52, Pierre Vuillemin a écrit : Le jeudi 14 août 2014 à 19:46 +0200, Samuel Gougeon a écrit : With Scilab 5.5.0 on Windows 7 x64: -->z = 2*%i z = 2.i -->disp([atan(z),%i/2*log((%i+z)/(%i-z))]) 1.5707963 + 0.5493061i1.5707963 + 0.5493061i I am on a 64-bit linux environment (Debian Jessie, Scilab 5.5.0), the result would be OS-dependent? It is possible. Some packages or/and some single functions -- including maths ones -- depend on the OS. The relation log(ab) = log(a) + log(b) only stands for the multi-valued logarithm function (or modulo pi). With the principal value of the log, defined as log(z) = ln(|z|) + i * arg(z) where -piIs this interval conventionnaly standard for the principal value, rather than -pi <= arg(z) < pi ? this is not true as soon as -pi It is, modulo 2.pi : i.2.pi [2.pi] ~ i.0 = 0 This is merely a problem of convention in the definitions, but this leads to differences in the value of the atan on its branch cuts. Indeed. Both results that you get from atan and log on Linux are correct, and equivalent. Results from win7 are equal and agree with the standard interval (-pi, pi]. Samuel ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users
Re: [Scilab-users] About the complex inverse tangent function
Le jeudi 14 août 2014 à 19:46 +0200, Samuel Gougeon a écrit : > Hello, > > Le 14/08/2014 15:12, Pierre Vuillemin a écrit : > > > 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 > With Scilab 5.5.0 on Windows 7 x64: > -->z = 2*%i > z = > 2.i > -->disp([atan(z),%i/2*log((%i+z)/(%i-z))]) > > 1.5707963 + 0.5493061i1.5707963 + 0.5493061i > I am on a 64-bit linux environment (Debian Jessie, Scilab 5.5.0), the result would be OS-dependent? > This is a strange result for the log expression, since we could expect > -1.57.. rather than 1.57... > 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) > with i = exp(i.pi/2), so : .. = ln(3) + 2.i.pi/2 = ln(3) + i.pi > Hence: i/2 * ln((i+z)/(i-z)) = i.ln(3)/2 - pi/2 : the real part is < > 0. > If there is an issue, it could be with log() rather than with atan(). > ... > > 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. > 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 > The relation log(ab) = log(a) + log(b) only stands for the multi-valued logarithm function (or modulo pi). With the principal value of the log, defined as log(z) = ln(|z|) + i * arg(z) where -pi ___ > users mailing list > users@lists.scilab.org > http://lists.scilab.org/mailman/listinfo/users ___ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users