Error when using distributive property

Hello!
The function below compares the output of two functions which run the same calculation. However, in one function the calculation's multiplications are distributed. It should output a matrix of 1s. However, it doesn't!
What's up with that?
function errorTest()
compute(1:100) == distributed(1:100)
function out = compute(a)
out = 10.1 * (a - 1);
end
function out = distributed(a)
out = 10.1 * a - 10.1;
end
end
Thanks!

 採用された回答

Oleg Komarov
Oleg Komarov 2011 年 7 月 26 日

0 投票

The propagation of floating approximations is different:
idx = abs(compute(1:100) - distributed(1:100)) > 2*eps
nnz(idx)
How many values over 2eps?

4 件のコメント

D G
D G 2011 年 7 月 26 日
function out = errorTest()
out = zeros(100, 2);
out(:, 1) = (compute(1:100) == distributed(1:100));
out(:, 2) = ((compute(1:100) - distributed(1:100)) > (2 * eps));
function out = compute(a)
out = 10.1 .* (a - 1);
end
function out = distributed(a)
out = 10.1 .* a - 10.1;
end
end
There is the updated code. It produces quite a few values over 2eps. There are even some over 500eps.
Oleg Komarov
Oleg Komarov 2011 年 7 月 26 日
Well, 500*eps = 1.11022302462516e-013; if you need precision to that point then it becomes an issue.
D G
D G 2011 年 7 月 26 日
I guess I had that backwards. If you remove the 2*, a lot of the answers are still different.
Oleg Komarov
Oleg Komarov 2011 年 7 月 26 日
Cannot really help you more than that, I don't have experience with distributed server.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by