[Scilab-users] Strange behavior of explicit vs implicit iteration

CRETE Denis denis.crete at thalesgroup.com
Mon Apr 25 10:25:16 CEST 2022


Hello,
A the error is of the order of %eps, isn’t it expected ?
This is related to the addition of “1” which is done after the loop for the first case, and before the loop in the second case. Initializing to A and B to 1 in the first case gives exactly the result of the second case:
…
for i=1:200
   A = 1; //0;
   B = 1; //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) = A ./ B; // (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))
M  =
   0.
ind  =
   1.

Best regards
Denis

De : users <users-bounces at lists.scilab.org> De la part de Federico Miyara
Envoyé : lundi 25 avril 2022 10:00
À : Users mailing list for Scilab <users at lists.scilab.org>
Objet : [Scilab-users] Strange behavior of explicit vs implicit iteration


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://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]<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>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20220425/fc0bbfed/attachment.htm>


More information about the users mailing list