From: jichao ? on 12 May 2010 03:07 The probability space is char prob range a1 0.001838 [0.998162, 1.0) a2 0.0975 [0.023162, 0.998162) a3 0.023162 [0.0, 0.023162) What I want is the arithmetic code for seq. a2a2a1a3a3.Here is my code to do so, global low high lowRange highRange lowRange = [0.998162, 0.023162, 0]; highRange = [1, 0.998162, 0.023162]; low = 0; high = 1; arithenc(2) arithenc(2) arithenc(1) arithenc(3) arithenc(3) function [] =arithenc(i) global high low lowRange highRange format long range = high - low; nhigh = low + range * highRange(i); nlow = low + range * lowRange(i); low = nlow; high = nhigh; fprintf('r = %.20f l = %.17f h = %.17f\n', range, low, high); The result is: r = 1.00000000000000000000 l = 0.02316200000000000 h = 0.99816199999999999 r = 0.97499999999999998000 l = 0.04574494999999999 h = 0.99636994999999995 r = 0.95062499999999994000 l = 0.99462270124999996 h = 0.99636994999999995 r = 0.00174724874999998560 l = 0.99462270124999996 h = 0.99466317102554747 r = 0.00004046977554750253 l = 0.99462270124999996 h = 0.99462363861094116 But the result like 0.99816199999999999 should be 0.9981612.However,if I do not specify the digits needed after the dot, I would lose some digits. Could you help me out? Thanks. PS:The sample data and code derviated directly from Data Compression: The Complete Reference. jichao.
From: us on 12 May 2010 03:55 "jichao ?" > fprintf('r = %.20f l = %.17f h = %.17f\n', range, low, high); > > The result is: > r = 1.00000000000000000000 l = 0.02316200000000000 h = 0.99816199999999999 > But the result like 0.99816199999999999 should be 0.9981612.However,if I do not specify the digits needed after the dot, I would lose some digits. > Could you help me out? Thanks. well... a FP evergreen... http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F us
From: jichao ? on 12 May 2010 04:08 "us " <us(a)neurol.unizh.ch> wrote in message <hsdmsq$g3$1(a)fred.mathworks.com>... > "jichao ?" > > fprintf('r = %.20f l = %.17f h = %.17f\n', range, low, high); > > > > The result is: > > r = 1.00000000000000000000 l = 0.02316200000000000 h = 0.99816199999999999 > > But the result like 0.99816199999999999 should be 0.9981612.However,if I do not specify the digits needed after the dot, I would lose some digits. > > Could you help me out? Thanks. > > well... a FP evergreen... > > http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F > > us Thanks. So do you mean there is no way to get the natural result 0.9981612, and we have to get the natural result by our eyes? jichao
From: us on 12 May 2010 04:16 "jichao ?" <jcyangzh(a)gmail.com> wrote in message <hsdnl3$iv8$1(a)fred.mathworks.com>... > "us " <us(a)neurol.unizh.ch> wrote in message <hsdmsq$g3$1(a)fred.mathworks.com>... > > "jichao ?" > > > fprintf('r = %.20f l = %.17f h = %.17f\n', range, low, high); > > > > > > The result is: > > > r = 1.00000000000000000000 l = 0.02316200000000000 h = 0.99816199999999999 > > > But the result like 0.99816199999999999 should be 0.9981612.However,if I do not specify the digits needed after the dot, I would lose some digits. > > > Could you help me out? Thanks. > > > > well... a FP evergreen... > > > > http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F > > > > us > Thanks. > So do you mean there is no way to get the natural result 0.9981612, and we have to get the natural result by our eyes? > > jichao yes... unless, of course, you come up with your own FPU and FP representation scheme, which would allow you to precisely binarize your particular number... be aware, though, there will always be another CSSMer, whose pet-number will get lost... us
From: Steven Lord on 12 May 2010 09:46 "jichao ?" <jcyangzh(a)gmail.com> wrote in message news:hsdnl3$iv8$1(a)fred.mathworks.com... > "us " <us(a)neurol.unizh.ch> wrote in message > <hsdmsq$g3$1(a)fred.mathworks.com>... >> "jichao ?" >> > fprintf('r = %.20f l = %.17f h = %.17f\n', range, low, high); >> > >> > The result is: >> > r = 1.00000000000000000000 l = 0.02316200000000000 h = >> > 0.99816199999999999 >> > But the result like 0.99816199999999999 should be 0.9981612.However,if >> > I do not specify the digits needed after the dot, I would lose some >> > digits. >> > Could you help me out? Thanks. >> >> well... a FP evergreen... >> >> http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F >> >> us > Thanks. > So do you mean there is no way to get the natural result 0.9981612, and we > have to get the natural result by our eyes? Why do you believe that exactly 9981612 ten-millionths is the "natural result"? How do you know that wherever you obtained your "probability space" data didn't simply round the data off to an appropriate number of decimal places, and that the "natural result" shouldn't be exactly 0.99816119999996667987568947284623784627351786157385678326? Or 0.998161 + (pi-1)/1e7? Either of those would round to 0.9981612. Binary computers storing numbers in IEEE double precision can only store a small subset of numbers exactly -- the vast majority of numbers are approximated, as described in the FAQ entry to which us pointed you. Roundoff is a fact of life; you need to be aware that it can pop up at the most inconvenient times, and prepare your code and/or your expectations for it. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: Different axis and xlim Next: Simulation of Repetitive Control System |