Test of Approximately Equality
46 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a value b and c. b and c are approximatly equal (b~c). They have +-5% difference.
I want to test of approximately equality..like this:
if b~c (with +-5% difference)
return something...
end
0 个评论
回答(3 个)
Jan
2012-6-17
You only have to decide if it should be 5% of the first or the second argument. Then:
if abs(b - c) < 0.05 * b
or
if abs(b - c) < 0.05 * max(b, c)
or
if abs(b - c) < 0.05 * min(b, c)
or
if abs(b - c) < 0.05 * (b + c) * 0.5
2 个评论
Stephen Nagy
2017-12-29
Your desired goal isn't entirely clear, but depending on the outcome you seek, the functions "uniquetol" and some of its related functions might be helpful.
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!