[Scilab-users] Strange behaviour of prod on rationals

Stéphane Mottelet stephane.mottelet at utc.fr
Fri Mar 20 14:10:02 CET 2020


Hello Frederico,

The problem is in simp() :

---> rlist(prod(a.num),prod(a.den),a.dt)
  ans  =

                                       2            3            4
    3.432D-17 + 1.230D-16s + 3.079D-16s + 5.709D-17s + 3.432D-17s
    --------------------------------------------------------------
                                           2            3   4
        1.0000004 + 61.501079s + 59.597296s + 14.304769s + s


---> simp(rlist(prod(a.num),prod(a.den),a.dt))
  ans  =

                                       2            3            4
    3.432D-17 + 1.230D-16s + 3.079D-16s + 5.709D-17s + 3.432D-17s
    --------------------------------------------------------------

                                  1

S.

Le 17/03/2020 à 10:30, Federico Miyara a écrit :
>
> Dear all,
>
> Look at this code (the coefficients are actually the result of pevious 
> calculations):
>
> NUM = [5.858D-09 + 2.011D-08*%s + 4.884D-08*%s^2 ...
> 5.858D-09 + 8.796D-10*%s + 7.028D-10*%s^2]
> DEN = [0.1199597 + 7.2765093*%s + %s^2 ...
>        8.336136 + 7.0282601*%s + %s^2]
> q = NUM./DEN
>
> Running it yields
>
>    5.858D-09 +2.011D-08s +4.884D-08s²  5.858D-09 +8.796D-10s +7.028D-10s²
>    ---------------------------------- ----------------------------------
>        0.1199597 +7.2765093s +s²            8.336136 +7.0282601s +s²
>
> This is, correctly, a two-component rational vector with the expected 
> numerators and denominators.
>
> Now let's evaluate
>
> q = prod(NUM./DEN)
>
> The prod documantation sys that the argument may be "an array of 
> reals, complex, booleans, polynomials or rational fractions". It 
> should provide the rational obtained by multiplying the twonumrators 
> and the two denominators. However, we get
>
>    3.432D-17 +1.230D-16s +3.079D-16s² +5.709D-17s³ +3.432D-17s⁴
>    ------------------------------------------------------------
>                                 1
>
> The numeratoris right, but the expected denominator has been just 
> replaced by 1
>
> However, rewriting the command as
>
> prod(NUM)/prod(DEN)
>
> we get the expected result:
>
>    3.432D-17 +1.230D-16s +3.079D-16s² +5.709D-17s³ +3.432D-17s⁴
>    ------------------------------------------------------------
>        1.0000004 +61.501079s +59.597296s² +14.304769s³ +s⁴
>
> This is quite strange!
>
> Now we repeat with simpler polynomials:
>
> NUM = [1-%s 2-%s]
> DEN = [1+%s 2+%s]
> q = NUM./DEN
>
> We get
>
>    1 -s  2 -s
>    ----  ----
>    1 +s  2 +s
>
> Now evaluate
>
> prod(NUM./DEN)
>
> The result is the expected one!
>
>    2 -3s +s²
>    ---------
>    2 +3s +s²
>
> The behavior seems to depend on the type of polynomials.
>
> Is this a bug or there is something I'm not interpreting correctly?
>
> Regards,
>
> Federico Miyara
>
> _______________________________________________
> 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/20200320/a8377ece/attachment.htm>


More information about the users mailing list