SKM
SKM

Reputation: 989

Matlab : Help in modulus operation

I am trying to implement a map / function which has the equation Bernoulli Shift Map

x_n+1 = 2* x_n mod 1

The output of this map will be a binary number which will be either 0/1.

So, I generated the first sample x_1 using rand. The following is the code. The problem is I am getting real numbers. When using a digital calculator, I can get binary, whereas when using Matlab, I am getting real numbers. Please help where I am going wrong. Thank you.

>> x = rand();
>> x

x =

    0.1647

>> y = mod(2* x,1)

y =

    0.3295

Upvotes: 0

Views: 489

Answers (2)

Hoki
Hoki

Reputation: 11812

I misunderstood your question because I focused on the assumption you had that the output should be binary [0 or 1], which is wrong.

To reproduce the output of the dyadic transformation as in the link you provided, your code works fine (for 1 value), and you can use this function to calculate N terms (assuming a starting term x0) :

function x = dyadic(x0,n)

x = zeros(n,1) ; %// preallocate output vector
x(1) = x0 ;      %// assign first term

for k=2:n
    x(k) = mod( 2*x(k-1) , 1) ; %// calculate all terms of the serie
end

Note that the output does not have to be binary, it has to be between 0 and 1.

In the case of integers, the result of mod(WhateverInteger,1) is always 0, but in the case of Real numbers (which is what you use here), the result of mod(AnyRealNumber,1) will be the fractional part, so a number between 0 and 1. (1 is mathematically excluded, 0 is possible by the mod(x,1) operation, but in the case of your serie it means all the successive term will be zero too).

Upvotes: 1

hiandbaii
hiandbaii

Reputation: 1331

The dyadic transformation seems to be a transformation from [0,1) continuous to [0,1) continuous. I see nothing wrong with your test code if you are trying to implement the dyadic mapping. You should be expecting output in the [0,1)

Upvotes: 2

Related Questions