Evaluating a function using the subs

1 回表示 (過去 30 日間)
Sincx
Sincx 2017 年 11 月 15 日
回答済み: Star Strider 2017 年 11 月 15 日
Why does the following fail to evaluate the function at x==6 and x==9?
p = 5E-3; L = 50E-3; x = 0:p:L; Q = x; y = Q(x==6*p)

回答 (1 件)

Star Strider
Star Strider 2017 年 11 月 15 日
If you run this:
Check = x - 6*p
you will see that it never evaluates to 0, so the condition is never met. This is called ‘floating-point approximation error’. The usual way of describing it is to note that in decimal notation, 1/3 evaluates to 0.3333... and multiplying that by 3 yields 0.9999..., not 1.
See Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? (link) for a more thorough explanation.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by