<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hello,</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">To me, <a
href="https://bugzilla.scilab.org/show_bug.cgi?id=15781#c2">as
already claimed there</a>, it's clear that, for a
complex-encoded number, not displaying its null imaginary part is
a bug, and the proposed patch is clearly welcome as well.<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Another regression very close to this
one, but with real numbers display, would deserve the same care :</div>
<div class="moz-cite-prefix">Scilab 5:</div>
<div class="moz-cite-prefix"><tt>-->[1e30 1e-30]</tt><tt><br>
</tt><tt> ans = </tt><tt><br>
</tt><tt> 1.000D+30 1.000D-30 </tt><tt><br>
</tt><br>
Scilab 6:<br>
</div>
<div class="moz-cite-prefix"><tt>--> [1e30 1e-30]</tt><tt><br>
</tt><tt> ans =</tt><tt><br>
</tt><tt> 1.000D+30 0.</tt><tt><br>
</tt></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">So, very small numbers are reduced to
strict 0...<br>
</div>
<div class="moz-cite-prefix">This is a bad implementation of the
variable format mode. The Scilab 5 one was correct, at least on
this point.<br>
</div>
<p>
Best regards<br>
Samuel<br>
</p>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Le 12/09/2019 à 10:26, Stéphane
Mottelet a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:3f0654df-5d03-ce02-f3e5-c1e537483d05@utc.fr">Hello all,
<br>
<br>
The subject has been already discussed a lot but I would like it
to be discussed again because I now have a real rationale to
promote a change in the way complex numbers with small imaginary
part are displayed. <br>
<br>
I don't know if some of you were aware of the clever technique of
complex-step derivative approximation, but until yesterday I was
not (see e.g.
<a class="moz-txt-link-freetext" href="http://mdolab.engin.umich.edu/sites/default/files/Martins2003CSD.pdf">http://mdolab.engin.umich.edu/sites/default/files/Martins2003CSD.pdf</a>).
Roughly speaking, using the extension of a real function
x->f(x) to the complex plane allows to compute an approximation
of the derivative f'(x0) at a real x0 without using a
substraction, like in the central difference formula
(f(x0+h)-f(x0-h))/2/h which is subject to substractive cancelation
when h is small. In Scilab most operators and elementary functions
are already complex-aware so this is easy to illustrate the
technique. For example let us approximate the derivative of
x->cos(x) at x=%pi/4, first with the central difference
formula, then with the complex step technique: <br>
<br>
--> format("e",24) <br>
<br>
--> h=%eps/128, x0=%pi/4 <br>
h = <br>
<br>
1.73472347597680709D-18 <br>
<br>
x0 = <br>
<br>
7.85398163397448279D-01 <br>
<br>
<br>
--> (cos(x0+h)-cos(x0-h))/2/h <br>
ans = <br>
<br>
0.00000000000000000D+00 <br>
<br>
<br>
--> imag(cos(x0+%i*h))/h <br>
ans = <br>
<br>
-7.07106781186547462D-01 <br>
<br>
<br>
--> -sin(x0) <br>
ans = <br>
<br>
-7.07106781186547462D-01 <br>
<br>
You can see the pathological approximation with central difference
formula and the perfect (up to relative machine precision)
approximation of complex-step formula. <br>
<br>
However, the following is a pity: <br>
<br>
<br>
--> cos(x0+%i*h) <br>
ans = <br>
<br>
7.07106781186547573D-01 <br>
<br>
We cannot see the imaginary part although seeing the latter is
fundamental in the complex-step technique. We have to force the
display like this, and frankly I don't like having to do that with
my students: <br>
<br>
--> imag(cos(x0+%i*h)) <br>
ans = <br>
<br>
-1.22663473334669916D-18 <br>
<br>
I hope that you will find that this example is a good rationale to
change the default display of Scilab. To feed the discussion, here
is how Matlab displays things, without having to change the
default settings: <br>
<br>
<br>
>> h=eps/128, x0=pi/4 <br>
h = <br>
1.7347e-18 <br>
x0 = <br>
0.7854 <br>
<br>
>> (cos(x0+h)-cos(x0-h))/2/h <br>
ans = <br>
0 <br>
<br>
>> cos(x0+i*h) <br>
ans = <br>
0.7071 - 0.0000i <br>
<br>
>> imag(cos(x0+i*h))/h <br>
ans = <br>
-0.7071 <br>
<br>
>> -sin(x0) <br>
ans = <br>
-0.7071 <br>
<br>
<br>
</blockquote>
<p><br>
</p>
</body>
</html>