Unknown x: x+1=1 in machine numbers

How do I set unknown variable x to find the largest x for which x + 1 = 1 in Matlab?

2 个评论

Yeah but if I want the smaller x for whick x=x+1? Is the same? And the largest x is the eps(y) for every y for which x+y=y?
Thank you for your answer!

请先登录,再进行评论。

回答(1 个)

x = eps(1)/2;
If x is larger than this, 1+x>1.

11 个评论

So..
x=eps(1)
while x+1>1;
x=x/2;
end
And I found the x?
EDITED by Matt Fig.... simply highlight the code and press the {} Code button...
Oh, you didn't say you were trying to get to this number by calculation! Sure:
x = 1;
while x+1>1
x = x/2;
end
OK..Therefore:
x=y;
while x+y>y;
x=x/2;
end
for every y?
And for the smaller x for which
x+9999=x
which x we put on original value? (
while x+9999<x;
x=x/2;?
)
Dude, please take the time to use the {} Code button!
Naw, that won't get it. You will have to zoom in on it once you find the x such that x/2+y is not greater than y.
Do you mean:
x=y;
while x+y<y;
x=x/2;
end
This is not correct
I think that the correct code for the largest x is this:
x=5000;
while x+5000>5000;
x=x/2;
end
Right?
What do you mean "the largest x"? That code returns a number that is not the largest x one can add to 5000 such that: (x+5000)==5000
The largest number x one can add to any y such that
(x+y)==y % is x=eps(y)/2
So this is how you check your code..
I mean the largest number x that recognized by "my" computer for which x+5000=x (so the x is a very small number and I try to find this small number)
Like I said, you will get close with the code I gave you above, then you can zoom in by looking at smaller differences than x/2. Is this homework?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

提问:

JIM
2012-11-2

Community Treasure Hunt

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

Start Hunting!

Translated by