Hi Frederico,

Rouding stuff is not a simple issue, but it's clear that your are not doing the computations in the same order, which could explain the difference. Here is a simpler example showing that the result depends on the order in which computations are done:

--> x=rand(10,1,"normal");

--> sum([1;x])-sum([x;1])
 ans  =

  -2.220D-16

Floating point addition is NOT associative. See e.g. https://en.wikipedia.org/wiki/Round-off_error

S.

Le 25/04/2022 à 10:00, Federico Miyara a écrit :

Dear All,

Here I have the following script, where I compute the same thing using two iteration methods:

alfa  =  rand(1,10);
Rpr  =  rand();
R  =  rand();
Z = rand(10,200);
G  =  zeros(1,200);
for  i=1:200
    A  =  0;
    B  =  0;
    for  k  =  1:10
A = A + Rpr*alfa(k) / (Z(k,i) + alfa(k)*(1 - alfa(k))*R); B = B + Rpr*(1 - alfa(k)) / (Z(k,i) + alfa(k)*(1 - alfa(k))*R);
    end
    G(i)  =  (1  +  A)  /  (1  +  B);
end

A  =  1;
B  =  1;
for  k  =  1:10
A = A + Rpr*alfa(k) ./ (Z(k,:) + alfa(k)*(1 - alfa(k))*R); B = B + Rpr*(1 - alfa(k)) ./ (Z(k,:) + alfa(k)*(1 - alfa(k))*R);
end
G1  =  A  ./  B;

[M,  ind]  =  max(abs(G- G1))
However, the last line shows that there are differences between both methods. They are tiny (near %eps), but I can't find nor imagine which is the reason.

NOTE: I kept the original formulas as in the script where the problem arised but changed the data. When I tried to use a simpler formula there was no difference.

Any idea?

Regards,

Federico Miyara

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> Libre de virus. www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

_______________________________________________
users mailing list
users@lists.scilab.org
http://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@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to