# Thread Subject: Problem in matlab IEE float

 Subject: Problem in matlab IEE float From: Kaze Date: 20 Jan, 2010 19:41:07 Message: 1 of 20 Hello, I need to solve a problem in matlab. Here is what I must do: Let F, set of all numbers in IEEE floating point, except NaN and inf, whith 7ff (in hexadecimal) exponent moved and numbers not normalized with superscript moved 000 (in hexadecimal) I realy don't know how should I start. After this I have to answer: 1. How many elements F has 2. What proportion of elements of F are in the interval [1, 2)? 3. What proportion of elements of F are in the interval [1/64, 1/32) ? 4. I need to determine by random selection the proportion of elements of F which satisfy the logical relationship: x*(1/x) == 1 Can someone please help me here :( I need this to be done by monday . Regards.
 Subject: Problem in matlab IEE float From: James Tursa Date: 20 Jan, 2010 20:18:05 Message: 2 of 20 "Kaze " wrote in message ... > Hello, > I need to solve a problem in matlab. Here is what I must do: > > Let F, set of all numbers in IEEE floating point, except NaN and inf, whith 7ff (in hexadecimal) exponent moved and numbers not normalized with superscript moved 000 (in hexadecimal) > > I realy don't know how should I start. > > After this I have to answer: > > 1. How many elements F has > 2. What proportion of elements of F are in the interval [1, 2)? > 3. What proportion of elements of F are in the interval [1/64, 1/32) ? > 4. I need to determine by random selection the proportion of elements of F which satisfy the logical relationship: x*(1/x) == 1 > > Can someone please help me here :( I need this to be done by monday . > > Regards. Obviously homework, very little of which has to do with MATLAB. What have you done on this so far? Any ideas? I will get you started. Think of the IEEE floating point (I presume double precision since you use the value 7ff for the exponent) as a 64-bit integer. And I presume you are not considering denormalized numbers. Then just count the integers that satisfy your criteria. (1) should be pretty easy to answer. For (2) and (3), just figure out what exponent bit patterns match the criteria and then the answer should easily follow. For (4), write some code to randomly pick numbers (this will be a bit tricky) from F and then test the condition. James Tursa
 Subject: Problem in matlab IEE float From: Kaze Date: 20 Jan, 2010 21:24:05 Message: 3 of 20 > Obviously homework, very little of which has to do with MATLAB. What have you done on this so far? Any ideas? > > I will get you started. Think of the IEEE floating point (I presume double precision since you use the value 7ff for the exponent) as a 64-bit integer. And I presume you are not considering denormalized numbers. Then just count the integers that satisfy your criteria. (1) should be pretty easy to answer. For (2) and (3), just figure out what exponent bit patterns match the criteria and then the answer should easily follow. For (4), write some code to randomly pick numbers (this will be a bit tricky) from F and then test the condition. > > James Tursa Hello James, Yes this a homework, the problem is that I'm real beginer in matlab. I've read about IEEE floating point in readme and I understand what they are but how should I write them in matlab ... I don't know. I have done some simple functions in matlab but now I'm over my head :( Regards.
 Subject: Problem in matlab IEE float From: Kaze Date: 23 Jan, 2010 18:04:02 Message: 6 of 20 Thanks for all the help. I don't think I can use num2vpi because I can't install anything on the computer since I don't have the permissions. I think I need another metode to get the numbers. A friend help me solve the last problem: *determine by random selection the proportion of elements of F which satisfy the logical relationship: x*(1/x) == 1 >> x=rand(1,n)*realmin; >> sum(x.*(1./x)==1) ans =      1 Now for the second problem, I think I can use this: *What proportion of elements of F are in the interval [1, 2)? >> x=rand(1,2)*realmin x =   1.0e-308 *     0.1541 0.4837 Can you please tell me If I did something wrong and help me with the other two ? Kind regards.
 Subject: Problem in matlab IEE float From: Walter Roberson Date: 23 Jan, 2010 18:10:50 Message: 7 of 20 Kaze wrote: > *What proportion of elements of F are in the interval [1, 2)? > >>> x=rand(1,2)*realmin rand(1,2) does not select values in the range [1,2); instead it creates a 1 x 2 matrix of random numbers.
 Subject: Problem in matlab IEE float From: James Tursa Date: 23 Jan, 2010 21:38:03 Message: 8 of 20 "Kaze " wrote in message ... > > I don't think I can use num2vpi because I can't install anything on the computer since I don't have the permissions. Well, unless you don't have permission to download anything I don't see why this would be an issue. These are just ASCII text files, m-files and C source code. You do have permission to create files, don't you? How would you ever learn MATLAB if you didn't have permission to create files? > I think I need another metode to get the numbers. Hmmm. What is wrong with the methods I showed you using direct counting or typecast? Neither one of them require you to download anything. > A friend help me solve the last problem: > *determine by random selection the proportion of elements of F which satisfy the logical relationship: x*(1/x) == 1 > > >> x=rand(1,n)*realmin; Amazing. You have managed to construct a vector x where absolutely *none* of the elements of x are in F. Exactly the opposite of the posed question. > >> sum(x.*(1./x)==1) Good ... except the x you are using is wrong. > Now for the second problem, I think I can use this: > *What proportion of elements of F are in the interval [1, 2)? > > >> x=rand(1,2)*realmin A total misuse of rand to get numbers in the interval [1,2). You need to read the doc on rand, and then look *very closely* at the examples I gave you with the direct counting or with typecast. Once you understand either one of them the answer to this question and the other interval question will be very easy. rand has nothing to do with it ... you can get the exact answer analytically with either of the methods I showed you. James Tursa
 Subject: Problem in matlab IEE float From: Kaze Date: 24 Jan, 2010 12:27:03 Message: 9 of 20 Sorry James, Please believe me that I'm over my head here and I'm not trying to ignore you or something like that. I've download the source code of num2vpi and vpi and is working. Happy for that. I'm not very sure if this is corect, but still : 2nd >> ieeemin = typecast(1,'int64') ieeemin =   4607182418800017408 >> ieeemax = typecast(2,'int64') ieeemax =   4611686018427387904 >> 2*(double(ieeemax)-double(ieeemin)) ans =   9.0072e+015 3rd >> ieeemax = typecast((1/32),'int64') ieeemax =   4584664420663164928 >> ieeemin = typecast((1/64),'int64') ieeemin =   4580160821035794432 >> 2*(double(ieeemax)-double(ieeemin)) ans =   9.0072e+015 If is not ok, what did I do wrong ? Regards.
 Subject: Problem in matlab IEE float From: James Tursa Date: 24 Jan, 2010 18:44:04 Message: 10 of 20 "Kaze " wrote in message ... > > I'm not very sure if this is corect, but still : > 2nd > >> ieeemin = typecast(1,'int64') > ieeemin = > 4607182418800017408 > >> ieeemax = typecast(2,'int64') > ieeemax = > 4611686018427387904 > >> 2*(double(ieeemax)-double(ieeemin)) > ans = > 9.0072e+015 > > 3rd > >> ieeemax = typecast((1/32),'int64') > ieeemax = > 4584664420663164928 > >> ieeemin = typecast((1/64),'int64') > ieeemin = > 4580160821035794432 > >> 2*(double(ieeemax)-double(ieeemin)) > ans = > 9.0072e+015 > > If is not ok, what did I do wrong ? Hmmmm ... well, now isn't that curious? You got the same answer for the number of elements of F in the interval [1,2) as in the interval [1/64,1/32). Does that seem right to you? Is that what you expect, or would you expect to get a different answer for these two questions? James Tursa
 Subject: Problem in matlab IEE float From: Kaze Date: 24 Jan, 2010 19:20:05 Message: 11 of 20 > Hmmmm ... well, now isn't that curious? You got the same answer for the number of elements of F in the interval [1,2) as in the interval [1/64,1/32). Does that seem right to you? Is that what you expect, or would you expect to get a different answer for these two questions? > > James Tursa What I aspect is to understand what I'm doing and to have no errors. Of course the problem has to be solved corecly. I get the same answer but I don't think is wrong. Thank you again for the help, I learn more from you than from my teacher. Kind regards.
 Subject: Problem in matlab IEE float From: Steven Lord Date: 25 Jan, 2010 04:01:52 Message: 12 of 20 "Kaze " wrote in message news:hj7m8j\$23m\$1@fred.mathworks.com... > Hello, > I need to solve a problem in matlab. Here is what I must do: > > Let F, set of all numbers in IEEE floating point, except NaN and inf, > whith 7ff (in hexadecimal) exponent moved and numbers not normalized > with superscript moved 000 (in hexadecimal) > > I realy don't know how should I start. > > After this I have to answer: > > 1. How many elements F has > 2. What proportion of elements of F are in the interval [1, 2)? > 3. What proportion of elements of F are in the interval [1/64, 1/32) ? > 4. I need to determine by random selection the proportion of elements of F > which satisfy the logical relationship: x*(1/x) == 1 The first three questions you can do without using MATLAB. Take a look at this Cleve's Corner article for more information about IEEE floating point numbers: http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf For question 4, two of the functions in the Data Type Conversion list of functions will help you in the random selection. http://www.mathworks.com/access/helpdesk/help/techdoc/ref/f16-6011seg05.html#f16-52710 -- Steve Lord slord@mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
 Subject: Problem in matlab IEE float From: Kaze Date: 25 Jan, 2010 06:20:21 Message: 13 of 20 "Steven Lord" wrote in message ... > > "Kaze " wrote in message > news:hj7m8j\$23m\$1@fred.mathworks.com... > > Hello, > > I need to solve a problem in matlab. Here is what I must do: > > > > Let F, set of all numbers in IEEE floating point, except NaN and inf, > > whith 7ff (in hexadecimal) exponent moved and numbers not normalized > > with superscript moved 000 (in hexadecimal) > > > > I realy don't know how should I start. > > > > After this I have to answer: > > > > 1. How many elements F has > > 2. What proportion of elements of F are in the interval [1, 2)? > > 3. What proportion of elements of F are in the interval [1/64, 1/32) ? > > 4. I need to determine by random selection the proportion of elements of F > > which satisfy the logical relationship: x*(1/x) == 1 > > The first three questions you can do without using MATLAB. Take a look at > this Cleve's Corner article for more information about IEEE floating point > numbers: > > http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf > > For question 4, two of the functions in the Data Type Conversion list of > functions will help you in the random selection. > > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/f16-6011seg05.html#f16-52710 > > -- > Steve Lord > slord@mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > Thank you, but this was needed to be solved in matlab. I'm going to look in the second link you provided, but as I said, I'm a beginner so ... I don't realy know what to chose from there. Kind regards
 Subject: Problem in matlab IEE float From: James Tursa Date: 25 Jan, 2010 06:54:06 Message: 14 of 20 "Kaze " wrote in message ... > > Hmmmm ... well, now isn't that curious? You got the same answer for the number of elements of F in the interval [1,2) as in the interval [1/64,1/32). Does that seem right to you? Is that what you expect, or would you expect to get a different answer for these two questions? > > > > James Tursa > > What I aspect is to understand what I'm doing and to have no errors. Of course the problem has to be solved corecly. > > I get the same answer but I don't think is wrong. Well, if you really think those results are correct then turn them in. Good luck. James Tursa
 Subject: Problem in matlab IEE float From: Kaze Date: 25 Jan, 2010 08:02:02 Message: 15 of 20 "James Tursa" wrote in message ... > "Kaze " wrote in message ... > > > Hmmmm ... well, now isn't that curious? You got the same answer for the number of elements of F in the interval [1,2) as in the interval [1/64,1/32). Does that seem right to you? Is that what you expect, or would you expect to get a different answer for these two questions? > > > > > > James Tursa > > > > What I aspect is to understand what I'm doing and to have no errors. Of course the problem has to be solved corecly. > > > > I get the same answer but I don't think is wrong. > > Well, if you really think those results are correct then turn them in. Good luck. > > James Tursa Thank you. Regards.
 Subject: Problem in matlab IEE float From: James Tursa Date: 26 Jan, 2010 02:44:03 Message: 16 of 20 "Kaze " wrote in message ... > "James Tursa" wrote in message ... > > "Kaze " wrote in message ... > > > > Hmmmm ... well, now isn't that curious? You got the same answer for the number of elements of F in the interval [1,2) as in the interval [1/64,1/32). Does that seem right to you? Is that what you expect, or would you expect to get a different answer for these two questions? > > > > > > > > James Tursa > > > > > > What I aspect is to understand what I'm doing and to have no errors. Of course the problem has to be solved corecly. > > > > > > I get the same answer but I don't think is wrong. > > > > Well, if you really think those results are correct then turn them in. Good luck. > > > > James Tursa > > Thank you. > > Regards. I would be interested in the answer that your professor has for #4. This question does not seem all that trivial to me. I can think of at least three ways of doing it (and have coded them up), but you either need some fancy code to generate the samples or make some assumptions about how the floating point processor behaves for different exponents to answer the question, neither of which I would expect a beginning student to understand. I am curious how your professor did it. James Tursa
 Subject: Problem in matlab IEE float From: Derek O'Connor Date: 26 Jan, 2010 07:30:21 Message: 17 of 20 "James Tursa" wrote in message > > I would be interested in the answer that your professor has for #4. This question does not seem all that trivial to me. I can think of at least three ways of doing it (and have coded them up), but you either need some fancy code to generate the samples or make some assumptions about how the floating point processor behaves for different exponents to answer the question, neither of which I would expect a beginning student to understand. I am curious how your professor did it. > > James Tursa This question is not trivial. Here is Prof Alan Edelman's answer (1994): http://www-math.mit.edu/%7Eedelman/homepage/papers/ieee.ps Derek O'Connor
 Subject: Problem in matlab IEE float From: James Tursa Date: 26 Jan, 2010 09:00:05 Message: 19 of 20 "Derek O'Connor" wrote in message ... > "James Tursa" wrote in message > > > > I would be interested in the answer that your professor has for #4. This question does not seem all that trivial to me. I can think of at least three ways of doing it (and have coded them up), but you either need some fancy code to generate the samples or make some assumptions about how the floating point processor behaves for different exponents to answer the question, neither of which I would expect a beginning student to understand. I am curious how your professor did it. > > > > James Tursa > > This question is not trivial. Here is Prof Alan Edelman's answer (1994): > > http://www-math.mit.edu/%7Eedelman/homepage/papers/ieee.ps > > > Derek O'Connor Don't have any s/w to open a ps file on the computer I am on at the moment. Will try at work tomorrow. A couple of my solutions were as follows: % 1st method % Direct method by generating random 64-bit integer bit patterns (as two % 32-bit pieces) and typecasting them as double precision bit patterns. x = uint32(floor(rand(n,1)*(2^32))); % Generate uniformly distributed 32-bit integers y = typecast(x,'double'); % Typecast them as IEEE double precision z = isnan(y) | isinf(y) | (y < realmin); % Figure out which ones are NaN, Inf, and denorm t = y(~z); % Get rid of the NaN, Inf, and denorm f = sum(t.*(1./t)==1) / numel(t); % Fraction of bit patterns satisfying the relationship disp(f); % 2nd method % Indirect method assumes that rand generates uniformly distributed bit patterns % down to the least significant bit after doing the +1 operation. Also assumes % that the floating point processor has the same rounding algorithm regardless % of the value of the exponent (probably a safe assumption, but still it is an % assumption). By looking only at the bit patterns for a fixed binary exponent % value (in this case the numbers between 1 and 2), we can extrapolate the % result for all exponent bit patterns (an assumption). x = rand(n,1)+1; % Generate uniformly distributed numbers in [1,2) f = sum(x.*(1./x)==1) / n; % Fraction of bit patterns satisfying the relationship disp(f); For critical work, I wouldn't rely on the 2nd method because of the assumptions made, but as it turns out for my PC the assumptions look to be correct since I get essentially the same answer as the first method which I trust to be uniformly distributed across F. The results for n=10000000:    0.84612180788734 % Method 1    0.84646010000000 % Method 2 I would hardly expect a beginning student to come up with this, which is why I was curious what the professor expected them to do. Thanks for the link ... hopefully I will be able to look at it tomorrow. James Tursa
 Subject: Problem in matlab IEE float From: James Tursa Date: 26 Jan, 2010 18:04:02 Message: 20 of 20 "Derek O'Connor" wrote in message ... > > This question is not trivial. Here is Prof Alan Edelman's answer (1994): > > http://www-math.mit.edu/%7Eedelman/homepage/papers/ieee.ps Couldn't even open it in MS Visio, which is supposed to handle ps files. So haven't been able to look at this yet. James Tursa

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.