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 Comments

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!

Sign in to comment.

Answers (1)

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

11 Comments

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
JIM
JIM on 2 Nov 2012
Edited: JIM on 2 Nov 2012
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!
Sorry..
Matt Fig
Matt Fig on 2 Nov 2012
Edited: Matt Fig on 2 Nov 2012
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.
JIM
JIM on 2 Nov 2012
Edited: JIM on 2 Nov 2012
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?

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

JIM
on 2 Nov 2012

Community Treasure Hunt

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

Start Hunting!