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 comentarios

eps(1)
JIM
JIM el 2 de Nov. de 2012
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!

Iniciar sesión para comentar.

Respuestas (1)

Matt Fig
Matt Fig el 2 de Nov. de 2012
x = eps(1)/2;
If x is larger than this, 1+x>1.

11 comentarios

JIM
JIM el 2 de Nov. de 2012
Editada: Matt Fig el 2 de Nov. de 2012
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 el 2 de Nov. de 2012
Editada: JIM el 2 de Nov. de 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;?
)
Matt Fig
Matt Fig el 2 de Nov. de 2012
Dude, please take the time to use the {} Code button!
JIM
JIM el 2 de Nov. de 2012
Sorry..
Matt Fig
Matt Fig el 2 de Nov. de 2012
Editada: Matt Fig el 2 de Nov. de 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 el 2 de Nov. de 2012
Editada: JIM el 2 de Nov. de 2012
Do you mean:
x=y;
while x+y<y;
x=x/2;
end
This is not correct
JIM
JIM el 2 de Nov. de 2012
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..
JIM
JIM el 2 de Nov. de 2012
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)
Matt Fig
Matt Fig el 3 de Nov. de 2012
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

JIM
el 2 de Nov. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by