フィルターのクリア

The most close approximation to zero

17 ビュー (過去 30 日間)
Eirini Gk
Eirini Gk 2016 年 4 月 7 日
コメント済み: Titus Edelhofer 2016 年 4 月 8 日
Hello, I want to ask you about the number of smaller approximation close to zero that matlab can understands. I mean I have a function and I wrote that If abs(....)<1e-15 (I want it =0 but because of small errors it has to be very very close to zero.) .. end
but when the number is close to this and has to read the loop it doesnt, so the function goes wrong. And also there many errors. Do you know if I can have a number closer to zero? (I wrote e-15 because I know that matlab gives till 15 digits after '.' when you have format long)
  4 件のコメント
Eirini Gk
Eirini Gk 2016 年 4 月 8 日
the first if for feval it is just because of the system that i have to solve (a circle with a line of a trajectory,it doesnt matter)
Titus Edelhofer
Titus Edelhofer 2016 年 4 月 8 日
Hi,
let me think: you say that for x0=0 the function newtonsmethod2 gives as result x1=3e-9, although x0=0 is the "better" (or exact? solution). In this case your newtonsmethod2 should see that x0=0 is in fact optimal and the error is to be searched there. Alternatives are you have a second order root, or the tolerances inside your newtonsmethod2 are not handled correctly or ...
Titus

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

採用された回答

Titus Edelhofer
Titus Edelhofer 2016 年 4 月 7 日
Hi,
there are some aspects to this question. The smallest number you can represent is much smaller:
realmin
ans =
2.2251e-308
But this is not what you are looking for. The accuracy is more what you are looking for:
eps
ans =
2.2204e-16
But keep in mind that the tolerance usually should be a relative tolerance, not an absolute one (difference of 10 degrees on earth makes much more of a difference than 10 degrees on the surface of the sun). So I would suggest to use something like
xExact = 42.0;
xIteration = 41.9;
while abs(xExact-xIteration) < 100*eps(xExact)
This way you have a relative error test. Note, the 100 is arbitrary and depends heavily on what you are really doing.
Titus
  3 件のコメント
Eirini Gk
Eirini Gk 2016 年 4 月 8 日
編集済み: Eirini Gk 2016 年 4 月 8 日
So Titus,you mean that I have to replace 1e-15 with 2.2204e-16 right ? Thanks both of you.
Titus Edelhofer
Titus Edelhofer 2016 年 4 月 8 日
No, not really. Your 1e-15 corresponds to "my" 100*eps(xExact).

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

その他の回答 (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