Different results for two equal functions

1 回表示 (過去 30 日間)
Beaya
Beaya 2013 年 10 月 27 日
コメント済み: Beaya 2013 年 10 月 27 日
I am comparing these two functions:
f = sqrt(x.^2+1.0)-1.0
g = x.^2./(sqrt(x.^2+1.0)+1.0)
x = [8^-6 8^-7, 8^-8]
Even though f = g, I get slightly different values e.g. for x = 8^-7 I get f(x) = 1.136868377216 160 e-13 and g(x) = 1.136868377216 096 e-13.
I'm guessing this has something to do with the reduction of significant digits, however I don't know which results are more reliable. My guess is that function f = sqrt(x.^2+1.0)-1.0 is more precise because we only have one x in it but I am not sure...

採用された回答

Walter Roberson
Walter Roberson 2013 年 10 月 27 日
The two functions you show algebraically yield identical values only for x = 0.
  3 件のコメント
Walter Roberson
Walter Roberson 2013 年 10 月 27 日
Apologies, I had a typo when I did the calculations. The two do come out the same.
To more precision the 8^(-7) answer is
1.136868377216095673908443130184740364*10^(-13)
so your g(x) formula is more precise.
Beaya
Beaya 2013 年 10 月 27 日
Thank you but do you know what might be the reason to that? I mean why g(x) is more precise?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by