Matlab: how to represent a real number as binary

Problem: How to use a continuous map - Link1: Bernoulli shift map to simulate a binary sequence?

Concept: A dyadic map, also called a Bernoulli shift map, is expressed as x(k+1) = 2x(k) mod 1 . Link2: Symbolic Dynamics explains that the Bernoulli map is a continuous map and is used as a shift map. This is explained below.

The numerical trajectory can be symbolized by dividing into the corresponding areas and assigning it as a symbol. A symbolic orbit is obtained by recording a sequence of characters corresponding to the sequential elements of the sections visited by a point in its orbit. You can learn a lot about the dynamics of a system by studying its symbolic orbits. This link also suggests that the Bernoulli shift map is used to represent symbolic dynamics.

Question:

How is the Bernoulli shift map used to generate a binary sequence? I tried this way, but this is not what the document in Link2 explains. So, I took the numerical output of the Map and converted to characters by the threshold value as follows:

 x = rand(); y = mod(2* x,1) % generate the next value after one iteration y = 0.3295 if y >= 0.5 then s = 1 else s = 0 

where 0.5 is the threshold value called the critical value of the Bernoulli map.

I need to represent the real number as fractions, as described here on page 2 of Link2.

Can someone please show how I can apply the Bernoulli shift map to create a symbolized trajectory (also called time series)?

Please correct me if my understanding is wrong.

How to convert real numerical time series to symbolized ones, for example, how to use the Bernoulli Map to model binary orbit / time series?

+6
source share
2 answers

You can, of course, calculate this in a real number, but you run the risk of encountering accuracy problems (depending on the starting point). If you are interested in studying orbits, you may prefer to work in representing a rational fraction. There are more efficient ways to do this, but the following code illustrates one way to calculate the series obtained from this map. You will see the definition of period-n on page 2 of your link 2. You can see from this code how you could easily work in real space of numbers as an alternative (in this case, the matlab rat function will restore a rational approximation from your real number) .

[EDIT] Now with a binary sequence made explicit!

 % start at some point on period-n orbit period = 6; num = 3; den = 2^period-1; % compute for this many steps of the sequence num_steps = 20; % for each step for n = 1:num_steps % * 2 num = num * 2; % mod 1 if num >= den num = num - den; end % simplify rational fraction g = gcd(num, den); if g > 1 num = num / g; den = den / g; end % recover 8-bit binary representation bits = 8; q = 2^bits; x = num / den * q; b = dec2bin(x, bits); % display fprintf('%4i / %4i == 0.%s\n', num, den, b); end 

Ach ... for completeness, here is the real version. Pure mathematicians should now look away.

 % start at some point on period-n orbit period = 6; num = 3; den = 2^period-1; % use floating point approximation x = num / den; % compute for this many steps of the sequence num_steps = 20; % for each step for n = 1:num_steps % apply map x = mod(x*2, 1); % display [num, den] = rat(x); fprintf('%i / %i\n', num, den); end 

And, for extra credit, why is this implementation quick, but stupid? (TIP: try setting num_steps to 50) ...

 % matlab vectorised version period = 6; num = 3; den = 2^period-1; x = zeros(1, num_steps); x(1) = num / den; y = filter(1, [1 -2], x); [a, b] = rat(mod(y, 1)); disp([a' b']); 

OK, this should be the answer, not the question, so let me answer my questions ...

This is fast because it uses the built-in (and optimized) Matlab filter function to handle the iteration (that is, in practice, iteration is performed in C rather than in M-script). It is always worth remembering the filter in Matlab, I am constantly wondering how it can be used for use in applications that do not look like filtering problems. filter cannot perform conditional processing, but does not support modular arithmetic, so how do we avoid this? Just because this card has the property that whole periods on the input card have whole periods on the output (because the card operation is multiplied by an integer).

This is stupid because it quickly gets to the above accuracy issues. Set num_steps to 50 and watch it start to get the wrong answers. What happens is, the number inside the filter operation becomes so large (10 ^ 14 order) that the bit that we really care (the fractional part) can no longer be represented in the same variable with double precision.

This last bit is a bit of a leak that has more to do with computation than mathematics - stick with the first implementation if your interest is in character sequences.

+6
source

If you want to deal with a rational type of inference, you will first need to convert the start term of your series to a rational number, if that is not the case. You can do it with

 [N,D] = rat(x0) ; 

Once you have the numerator N and the denominator D , it is very easy to calculate the series x(k+1)=mod(2*x(k), 1) , and you don’t even need a loop.

for part 2*x(k) , this means that all Numerator(k) will be multiplied by the sequential power of 2, which can be done using matrix multiplication (or bsxfun for the function lover):
therefore 2*x(k) => in Matlab N.*(2.^(0:n-1)) (N is a scalar, numerator x0, N is the number of terms you want to calculate).

The operation Mod1 also be easily translated to a rational number: mod(x,1)=mod(Nx,Dx)/Dx ( Nx and Dx are the numerator and denominator of x .

If you do not need to simplify the denominator, you can get all the numerators of the series in one line:

 xn = mod( N.*(2.^(0:n-1).'),D) ; 

but for visual comfort it’s sometimes better to simplify, so consider the following function:

 function y = dyadic_rat(x0,n) [N,D] = rat(x0) ; %// get Numerator and Denominator of first element xn = mod( N.*(2.^(0:n-1).'),D) ; %'// calculate all Numerators G = gcd( xn , D ) ; %// list all "Greatest common divisor" y = [xn./G D./G].' ; %'// output simplified Numerators and Denominators 

If I start with the example provided in your wiki link ( x0=11/24 ), I get:

 >> y = dyadic_rat(11/24,8) y = 11 11 5 2 1 2 1 2 24 12 6 3 3 3 3 3 

If I start with the example given by Rattus Ex Machina ( x0=3/(2^6-1) ), I also get the same result:

 >> y = dyadic_rat(3/63,8) y = 1 2 4 8 16 11 1 2 21 21 21 21 21 21 21 21 
+4
source

Source: https://habr.com/ru/post/986856/


All Articles