稳定性(数值分析) [英] Stability (Numerical analysis)
本文介绍了稳定性(数值分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到满足以下方程式的最大机器编号x:x + a = a,其中a是给定的整数. (我不允许使用eps.)
I'm trying to find the max machine number x that satisfies the following equation: x+a=a, where a is a given integer. (I'm not allowed to use eps.)
这是我的代码(实际上不起作用):
Here's my code (which is not really working):
function [] = Largest_x()
a=2184;
x=0.0000000001
while (x+a)~=a
x=2*x;
end
fprintf('The biggest value of x in order that x+a=a \n (where a is equal to %g) is : %g \n',a,x);
end
任何帮助将不胜感激.
推荐答案
答案是eps(a)/2
.
eps
是下一个浮点数的差,因此,如果对浮点数加一半或更少,则不会改变.例如:
eps
is the difference to the next floating point number, so if you add half or less than that to a float, it won't change. For example:
100+eps(100)/2==100
ans =
1
%# divide by less than two
100+eps(100)/1.9==100
ans =
0
%# what is that number x?
eps(100)/2
ans =
7.1054e-15
如果您不想依赖eps
,则可以将数字计算为
If you don't want to rely on eps
, you can calculate the number as
2^(-53+floor(log2(a)))
这篇关于稳定性(数值分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文