Smallest real number which has no inverse in Matlab.

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hello everybody.

I am trying to find a real number x so that x is the smallest
number bigger than 1 which can be represented by the Matlab but 
which doesn't have an inverse which could be represented in Matlab. 
Now, the smallest number t which could be added to 1 so that 1 ~= (1+t)
is 2^-52. So, I wrote the following program:

x = 1;
y = x;
while x == y
  x = x + 2^-52;
  y = 1/(1/x);
end
x

Obviously, that program should find the required number. The 
problem is that it take a *long* time to find that number (I tried
to run the program for 6 hours on Athlon 1333, and still no success).
Is it somehow possible to find the required number quicker?

0
Reply this (338) 11/15/2006 7:33:26 PM

See related articles to this posting


ddtl wrote:
> Hello everybody.
>
> I am trying to find a real number x so that x is the smallest
> number bigger than 1 which can be represented by the Matlab but
> which doesn't have an inverse which could be represented in Matlab.
> Now, the smallest number t which could be added to 1 so that 1 ~=3D (1+t)
> is 2^-52. So, I wrote the following program:
>
> x =3D 1;
> y =3D x;
> while x =3D=3D y
>   x =3D x + 2^-52;
>   y =3D 1/(1/x);
> end
> x
>
> Obviously, that program should find the required number. The
> problem is that it take a *long* time to find that number (I tried
> to run the program for 6 hours on Athlon 1333, and still no success).
> Is it somehow possible to find the required number quicker?

Generally, you will always get a round off error when representing
floating point numbers on a computer. This especially the case in your
example. The inverse of x will almost allways suffer from this, and is
also depending on the standard that is used for floating point
calculations. You can't even be sure that 1/1 equals 1 exactly (even if
it does when I test it in Matlab). When comparing x with y, you should
see if the difference is below a precision limit of your choice. You
should also take a look at the eps function if you haven't done so
already.=20

Regards,=20
J=F8ger

0
Reply jogerh2032 (17) 11/15/2006 7:58:11 PM

In article <obqml21jgi6shm35bkg4mub9n93vbn3edv@4ax.com>, ddtl
<this@is.invalid> wrote:

> Hello everybody.
> 
> I am trying to find a real number x so that x is the smallest
> number bigger than 1 which can be represented by the Matlab but 
> which doesn't have an inverse which could be represented in Matlab. 
> Now, the smallest number t which could be added to 1 so that 1 ~= (1+t)
> is 2^-52. So, I wrote the following program:
> 
> x = 1;
> y = x;
> while x == y
>   x = x + 2^-52;
>   y = 1/(1/x);
> end
> x
> 
> Obviously, that program should find the required number. The 
> problem is that it take a *long* time to find that number (I tried
> to run the program for 6 hours on Athlon 1333, and still no success).
> Is it somehow possible to find the required number quicker?
-------------------------
  I can't imagine what led you to such a problem as this, ddtl, but it
does have a definite answer, and that is the number x =
1.414213573163048743, or in matlab's format hex, 3ff6a09e6964b6ac.  I
don't wonder that your while loop wasn't finished after a mere six hours,
since it would have required some 1.865e+15 (almost two quadrillion) trips
through the loop to reach that number, starting as far back as x = 1 and
only adding 2^(-52) each time.

  What makes a solution possible in practical terms is the fact that no
value of x below sqrt(2) can possibly fail to achieve equality of x and
1/(1/x).  To demonstrate this, start with the assumption that 1 < x < 2. 
Then you can write the result of the first reciprocal as:

 t = 1/x + e1

where e1 is the round off error, and where, since 1/2 < t < 1, we have
abs(e1) <= 2^(-54).  This is a guaranteed property of division with double
precision IEEE 754 numbers - that is, the round off error cannot exceed
half the value of the least bit position, which for t is worth 2^(-53). 
The next step is:

 y = 1/t + e2

where, since 1 < y < 2, we have abs(e2) <= 2^(-53), again because of round
off precision requirements.

  Given the meaning of e1 and e2, the previous two equations are
mathematically exact equations, and we can manipulate with them as such. 
Combining them gives

 y = 1/(1/x + e1) + e2 = x - (x^2/(1+e1*x))*e1 + e2,

and if we multiply both sides by 2^52 and do a transpose, we obtain

 2^52*y - 2^52*x = -(x^2/(1+e1*x))*(2^52*e1) + (2^52*e2)

Because the fractional parts of x and y have only 52 bits, the left side
of this last equation must be an integer, and therefore so must the right
side.  However, abs(2^52*e1) <= 1/4 and abs(2^52*e2) <= 1/2.  This tells
us that the only way we will ever get a non zero integer value for the
right side is to have the factor x^2/(1+e1*x) be greater than or equal to
2.  That in turn means that x must be at least the square root of 2 (or
within round off error of it.)

  That fact being established, the only modification needed on your
while-loop method to speed things up is to start with x = sqrt(2), or to
play safe, a small amount below that.  I started with x =  1.414213562,
and let it run until it finally stopped some ten or twenty minutes later
(I forgot to time it) and arrived at the number above.

Roger Stafford
0
Reply ellieandrogerxyzzy (4806) 11/16/2006 6:24:28 AM
comp.soft-sys.matlab 203225 articles. 527 followers. Post

2 Replies
136 Views

Similar Articles

[PageSpeed] 54


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

How can I load complex and real numbers into MatLab
Hi I have a rather simple problem. I have a file containing real and complex numbers in distinct colomns. The file is in a normal ANSI txt format, with tap. as separator. ex. 0.0034 0.00032 - i0.0004 0.0012 0.00345 + i0.0112 I have tried with load, dlmread, and fscanf. but it don't seems to work. Are there anyone there have any idea on how I can load this data into matlab as a matrix. /Anders Hi If you know the exact structure of the file (i mean, let all the odd numbered columns contain real values etc) then, get the each line and use strread to separate them....this is mere an ide...

Largest and smallest real numbers Fortran is capable of handling
How do I find the largest and smallest real numbers my Fortran77 compiler (gcc) is capable of handling. For example, in C, I'd check (if I remember correct) REAL_MAX and REAL_MIN in the header file limits.h. How do I do this in Fortran77? eric948470 <eric948470@gmail.com> wrote: > How do I find the largest and smallest real numbers my Fortran77 > compiler (gcc) is capable of handling. For example, in C, I'd check > (if I remember correct) REAL_MAX and REAL_MIN in the header file > limits.h. How do I do this in Fortran77? You look in the compiler document...

Real-Time Workshop use Embedded Matlab Function to generate random numbers
Hi everyone, In the Real Time Workshop I am trying to use in an embedded Matlab function in Stateflow the two function “rand” and “round”, but I always get the following error: Failed to eliminate a use of the MATLAB function 'rand/round'. For non-simulation builds, uses of unsupported MATLAB functions are eliminated if they do not effect the model outputs. The code that I am using is the seguent: function calculation eml.extrinsic('rand','round'); random_number=rand(1,9); Status_vector_cells=round(0+(99-0).*random_number); I would like please to ...

Forcing Matlab to use real numbers instead of scientific notation on axis labels
How do I force Matlab to use the actual values as axis labels instead of it automatically switching to scientific notation? I have a plot that ranges from 200 to 500 on the x-axis, and from -9000 to +9000 on the y-axis. When I plot the data, the figure uses the y-scale as -1x10^4 to +1x10^4. I want it to say -10,000 to +10,000. I'm sure there's a fairly easy way to do this, but I couldn't find it in the help. Anbody know? Thanks. A.J. wrote: > > > How do I force Matlab to use the actual values as axis labels > instead > of it automatically switching to scientifi...

matrix function that compare a list of real numbers with a real number
I need a function which accepts as input a list of real numbers, and a real number X and which returns to the output: • The number of how many times the number (X) appear in the table • The location where this number appears in the table • A table that will have the value 0 in the positions where (X) appears and the value -1 in the remaining positions • A table(matrix) where the elements of the original matrix that is larger than the input number (X) will be replaced with the maximum number of the original table • A vector which will contain all the unique elements of the input table whic...

Computation using real numbers as opposed to rational approximations to real numbers
Since computers doing credible numerical analysis are going to spend most of their time waiting for data to arrive from the other side of the universe, perhaps we can find a way to keep exotic CPU's busy while waiting. Would anyone care to speculate on the possibility of using (recursively computable) continued fractions to do arithmetic with actual real numbers, as opposed to rational approximations to real numbers? Unless you throw sand in the gears by deliberately introducing pathological real numbers (e.g. ones whose continued fraction representation would involve frequent prim...

Complex Numbers to Real numbers
What is the best way to convert a complex number say "5 - .2i" to a real value? The function real returns the real part, but if I need a complex number as a real value, is that the best way to convert it to a real value? thx In article <eef8b35.-1@webx.raydaftYaTP>, Mark <mktw@yahoo.com> wrote: > What is the best way to convert a complex number say "5 - .2i" to a > real value? > > The function real returns the real part, but if I need a complex > number as a real value, is that the best way to convert it to a real > value? > > thx ...

change from real numbers to complex numbers
Hi guys, I have a matrix (A) which contains all complex numbers. I did this: X = real(uint8(A)) I got a matrix (X) that contains all real numbers. is it possible to change the matrix (X) back to its original matrix (A)? Thanks in advance Mohamad Hi, A=rand(5,1)+i*rand(5,1) R=real(A) I=imag(A) B=complex(R,I) C=R+i*I J�r�me Mohamad wrote: > > > Hi guys, > > I have a matrix (A) which contains all complex numbers. > > I did this: > > X = real(uint8(A)) > > I got a matrix (X) that contains all real numbers. > > is it possible to change the matrix...

converting binary numbers to real numbers
Please tell me how to convert binary numbers to real numbers. How to do the programme? Thank you. In article <ef0e4d4.-1@webx.raydaftYaTP>, "malar nayana" <mv_nayana@yahoo.com> wrote: > Please tell me how to convert binary numbers to real numbers. How to > do the programme? > > Thank you. ------------------------- What form are your binary numbers in? Strings, vectors of 1's and 0's, what? Do they represent integers, or if not what determines their binary points? (Remove "xyzzy" and ".invalid" to send me email.) Roger Staffor...

real number to 16 bit signed number
hi a) i want to convert a real number to 16 bit signed binary number. the real number is 2E15-1.so how should i do it.do we have any default packages for that. thanks hari "hari" <hari_pro@yahoo.com> wrote in message news:a4a587f1.0404272014.340b51d0@posting.google.com... > hi > a) i want to convert a real number to 16 bit signed binary number. > the real number is 2E15-1.so how should i do it.do we have any > default packages for that. > Assuming you mean SIGNED from Numeric_std, you could use library IEEE; use IEEE.NUMERIC_STD.all; .... signal S...

Change real numbers to complex numbers, very easy question
Dear friends, I want to write a subroutine. This is an easy subroutine however I don't know Fortran so not easy for me. First of all I want to multiply all matrix element with imaginary(i), for instances, I have B matrix all numbers are real, as 231 or 352 they will become 213i or 352i. w is real number, M, A, B and C are known matrices. B will change to imaginary Bi matrix. So How can I obtain F matrix? Can you help me? Sincerely.. F = -(w^2)*(M+A)+(imaginary(B))*w+C On Tuesday, March 4, 2014 1:10:32 PM UTC-5, Salim Tamer wrote: > Dear friends, > I want to write a s...

Real numbers
Does anyone know if negative numbers really exists or if it is only a myth spread by mathematicians. /Jultomten jultomten wrote: > > > Does anyone know if negative numbers really exists or if it is only > a > myth spread by mathematicians. > > /Jultomten If one writes -1 on a piece of paper is that a negative number, or simply a symbol we call a negative number? If I have a bunch of apples in a basket I cannot count a negative number of apples in the basket. However, my mortage company continues to tell me that I owe them more money than they gave me. So is the differen...

Returning the real numbers withing a vector containing imaginary and real
Hi, i have a vector containing real and imaginary numbers, what can i do to return only the real numbers within that vector, i.e a = [3+0.2i, 5, 4+0.5i, 6] and to give ans = 5 6 any help greatly appreciated, last post about the return positive in vector was really helpful Janice wrote: > > > Hi, i have a vector containing real and imaginary numbers, > > what can i do to return only the real numbers within that vector, > > i.e a = [3+0.2i, 5, 4+0.5i, 6] > > and to give ans = 5 6 > > any help greatly appreciated, > > last post about the return positiv...

Smallest number
Hi, Is there a way, via refelction, to know what's the smallest representable positive number on a given implementation of St? Thanks Fernando, > Is there a way, via refelction, to know what's the smallest > representable positive number on a given implementation of St? Do you need a portable solution, or will Float class>>fmin do ? If not then I seem to remember that Didier Bessets' book has a routine to discover the smallest representable Float, but I can't remember the details offhand. It was something like "divide by 2 until an Underf...

Convert Floating point number into fixed point number in Matlab
I have a GUI Matlab program using floating point number. My job is to convert floating number to fixed point number. I found some information about "fixed-point designers", but I dont know how to use that for big program with many functions and GUI.Do you have any experiences for these problems?Thank you. ...

New real number handling using some feedback from studying complex numbers
It's in java and for a different purpose, but maybe the reals should extend like this in trig. http://sites.google.com/site/jackokring/Home/mith-the-maths-package-for-java-me Cheers Jacko ...

Big mystery: why my uitable display complex numbers when the number in the structure are real?!!!!
Hello! Uitable is driving me crazy, I can;t understand that's happening. I am working on a GUI, and at some stage I display in a uitable data I have stored previously in a structure. This data come from calculations on energy data, which are real numbers (not complex). My uitable displays my numbers as if they were complex numbers! For example, if I am displaying the following matrix: A=[NaN 2; 8 3]; I see in my uitable: NaN+0.0000i 2+0.0000i 8+0.0000i 3+0.0000i (Even the NaN appear like NaN+0.0000i that's crazy!!!!) That's incredible!!! When I load my structure...

Mac Net Apps share trend analyzed with real numbers and real statistics!
Hi, Alan Baker Take the Net Apps share for Windows, Mac and Linux. Total those shares and calculate the share of the each OS based on that total. You get the OS share of the 3 major platforms, and ignore the mobile and misc. OS shares. The Mac share increases have declined steadily since early 2009. See this chart: http://docs.google.com/fileview?id=0BxuJGTDTmSZ1ZDU2NTA3OWMtZmU4ZS00M2NkLTg5NGUtNGVkMmExYTIzMGQ5&hl=en Windows share erosion has, no big surprise, correspondingly slowed. see this chart: http://docs.google.com/fileview?id=0BxuJGTDTmSZ1NzFmZGIzM2MtZDY5Yi00Mz...

"A random real number will be on a computables list to an infinite number of digits"
True / False / Other ? ____ "All finite subsequences of a random real number will be on a computables list" True / False / Other ____ "All digits of a random real number are covered in all finite subsequences of that number" True / False / Other ____ "If you have the list of computables, a random real number can be on it to an infinite number of digits, and yet not be on the list" True / False / Other ___ Herc -- Have you now or have you ever been a member of the antidisestablishmentarianism party? |-|erc wrote: > > True / False / Other ? &...

why Matlab 2013a solve() does not return all real solutions when using 'Real' option?
according to http://www.mathworks.com/help/symbolic/solve.html it says "If you need a solution in real numbers, use Real, true" Ok, lets see: --------------- clear all; syms rt; t1=pi*(((rt/2 + 74798900)^3/132700000000)^(1/2) + ... ((rt/2 + 1632333680397517/4194304)^3/132700000000)^(1/2)); t2=3.7455e+08; sol2=solve(t1 == t2, rt); --------------- vpa(sol2,6) 1.65005e10 1.07669e9 - 1.23455e9 - 1.36189e9*i - 1.23455e9 + 1.36189e9*i So, one would assume using 'Real', true, would now return only first 2 solutions...

call any usa REAL telephone number from the internet at pulver freeworld for .06 per minute
You dreamed of it - now you can have it ..06 per minute - call any telephone in the USA! $10 a month to RECEIVE calls with YOUR OWN REAL PHONE NUMBER! All via your Pulver freeworld account No gimmicks No hidden fees No extra monthly charges You are billed ONLY for the minutes you use and they roll to the next month if you don't use them. First month buy 650 minutes and they roll forever until you use them up. Pay by paypal, only. For $50, get a REAL telephone number ANYONE can call and 650 minutes! You must continue to pay $10 a month for the phone number. Rec...

convert string number to real number
i am parsing a cell phone bill to get a list of all numbers and the total talktime spend on each number. i already have a unique list of the phone numbers. now i must go through the list of numbers and add up the totals for each number. on the bill, each line has a few fields,one field containing the phone number, another field containing the number of minutes on that call. the bill is comma delimited. here is the function i wrote to get one number at a time's total talktime. def getsinglenumbertalktime(number,talktime): for line in file[0:-2]: if number in line: li=line.split(&#...

Finding a Number in Matlab
Is there a way to find a location of a specific number in a matrix. For instance, if have the following matrix: A = [1 3 2] [9 5 7] [8 4 6] Is there anyway to find the location of 5 (i.e. for matlab to return something like (2 2))? Thank You Leif Sandager I do not know if you can get the (2,2) but you can know that its index position is 5 by using find(a==5) you will get ans=5 which means it is in the fifth position. Similarly find(a==4) will give you an answer of 6. It counts them top to bottom and left to right, column by column. [I,J] = find(A==5) Note that if there is...

Precision of real numbers
I meet a strange problem regarding precision of real numbers. The following is my test program. PROGRAM test IMPLICIT NONE INTEGER, PARAMETER:: DBL=SELECTED_REAL_KIND(15,307) REAL(DBL):: time1,time0,timen,time_i,time_incr INTEGER::i,n time0=0._dbl timen=1._dbl n=5 time_incr=(timen-time0)/n DO i=1,n time_i=time_incr*real(i,dbl)+time0 write(*,'(ES25.15)')time_i ENDDO END PROGRAM TEST I am expecting 2.000000000000000E-01 4.000000000000000E-01 6.000000000000000E-01 8.000000000000000E-01 1.000000000000000E+00 However, when I run the program, I obtain the following 2.0...