[Scilab-users] Problems arising from truncation of %pi

Stéphane Mottelet stephane.mottelet at utc.fr
Wed Jan 6 10:00:59 CET 2021


Of course, this does only work for integer multiples of %pi. This plot 
illustrates well Antoine's remark:

x=(10^15*%pi)+(0:0.001:2*%pi);
plot(sin(x));

error

I like new year's jokes !

S.

Le 06/01/2021 à 09:49, Stéphane Mottelet a écrit :
>
> I do not agree with your answer. Doing *by hand* the shift to a 
> principal period  of sin () solves the problem. For example, here is a 
> plot of sin(x) vs sin(x-floor(x/2/%pi)*%pi*2) for large values of x:
>
> x = (10^[1:16])*%pi
> sx = sin(x-floor(x/2/%pi)*%pi*2)
> plot("ln",x,sin(x),'-o',x,sx,'-o')
> legend("$\Large\sin x$","$\Large\sin 
> \left(x-2\pi\left\lfloor\frac{x}{2\pi}\right\rfloor\right)$",3)
>
> error
>
> I suppose that the hardware implementation used by the compiler when 
> using the standard math library does not use this simple trick because 
> it would decrease the floating point performance.
>
>
> S.
>
> Le 06/01/2021 à 09:14, Jean-Yves Baudais a écrit :
>> Hello,
>>
>> Le 05/01/2021 à 09:19, Federico Miyara a écrit :
>>> --> sin(%pi)
>>>   ans  =
>>>     0.0000000000000001224647
>>
>>
>> You face the limited precision of all numerical calculus. See
>> --> help %eps
>>
>> It has no sense to use 23 digits with a precision of 2.22E-16, the 
>> 7th last digits are noise.
>>
>>
>>> --> sin(1e10*%pi)
>>>   ans  =
>>>    -0.0000022393627619559233
>>>
>>> --> sin(1e15*%pi)
>>>   ans  =
>>>    -0.2362090532517409080526
>>
>>
>> All is consistent with the definition of the precision. A toy example:
>> --> a=2;
>> --> b=sqrt(2);
>> --> a-b^2
>>
>> You expect zero because you do symbolic calculus, not Scilab.
>>
>>
>>> The Wolfram Alpha site yields the correct value 0 in all cases 
>>> (using their own pi).
>>
>>
>> Because it uses symbolic calculus. So, if you want more precision 
>> with Scilab you should change the standard used, but maybe some 
>> tricks in your code can solve the problem... Or maybe you need 
>> symbolic calculus tool.
>>
>> --Jean-Yves
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users 
>>
> -- 
> Stéphane Mottelet
> Ingénieur de recherche
> EA 4297 Transformations Intégrées de la Matière Renouvelable
> Département Génie des Procédés Industriels
> Sorbonne Universités - Université de Technologie de Compiègne
> CS 60319, 60203 Compiègne cedex
> Tel : +33(0)344234688
> http://www.utc.fr/~mottelet
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users

-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210106/ccfaac42/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: error.gif
Type: image/gif
Size: 5581 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20210106/ccfaac42/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: error.gif
Type: image/gif
Size: 6463 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20210106/ccfaac42/attachment-0001.gif>


More information about the users mailing list