how to permute the sequence? why it takes to much time .

wh

7 Commenti

x(1)=0.27;
q=0.3;
for i=2:65736;
if x(i-1)>=0 & x(i-1)<q
x(i)=(x(i-1)/q);
elseif x(i-1)>=q & x(i-1)<=0.5
x(i)=(x(i-1)-q)/(0.5-q);
else
x(i)=(1-x(i-1));
end
end
N=201;
X=[x(N:end)];
L=65536;
flag=zeros(1,L);
T = num2cell(randperm(65536, 65536));
T=flag;
for i=1:65536;
j(i)=mod(floor(X(i)*10^15),L)+1;
if (j==i)|(flag(j)==1)
j(i)=mod(floor(X(i)*10^15),L)+1;
else
flag(j)=1; T=j;
end
end
is it ok..?
In lines 19 & 21 of your posted code, can you explain why you are using j(i) and not j (as given in the screenshot of the algorithm posted by you). It seems strange as in the 20th line, you do use the expression (j == i) (instead of j(i) == i or something else), which actually returns a big logical vector (since you are increasing the size of j in each iteration of the loop).
Also, do try preallocating x (and j if you actually intend to create a vector j) to the required size to improve performance of your code.
"why it takes to much time"
The lines
j(i)=mod(floor(X(i)*10^15),L)+1;
if (j==i)|(flag(j)==1)
use most of the time.
Jan
Jan il 25 Giu 2019
Modificato: Jan il 25 Giu 2019
This is a waste of time:
flag = zeros(1,L);
T = num2cell(randperm(65536, 65536)); % ???
T = flag;
The first definition of T is overwritten directly, so omit the marked line.
10^15 is a very expensive power operation, while 1e15 is a cheap constant.
This is not clear to me:
j(i)=mod(floor(X(i)*10^15),L)+1;
if (j==i)|(flag(j)==1)
j(i)=mod(floor(X(i)*10^15),L)+1;
You assigne the same value twice to j(i) if flag(j) is 1 and j==i. The problem is, that j is a vector and then this means:
if all(j==i) | all(flag(j)==1)
Is this really wanted?
I'm convinced you mean:
SORRY! I break up editing my answer because the interface of this forum drives me crazy with its annoying opinions about automagical indentation and auto-completing. See https://www.mathworks.com/matlabcentral/answers/438664-strange-behavior-of-the-editor-in-the-forum .
so how we initialize the permutation sequence T.?
if given below is waste of time
flag = zeros(1,L);
T = num2cell(randperm(65536, 65536)); % ???
T = flag;
@Sultan: How could I know this? You did not explain what "initializing the permutation sequence" means. All I know is using an expensive call of num2cell(randperm()) is wasted, if you replace the result in the next line.
Please read your question again. Remember, that the readers cannot know, what this means: "Iterate the PWLCM x_i+1=F(x_i) by using (2) for N_0 times to get rid of the transient effect." The first sentence is not clear for the readers already. Then all we can do is to find some inconsistencies in your code, e.g. you use j(i) sometimes, but the complete vector j other times.
What's really missing from the question is some context. We've been given the middle of an algorithm with no explanation of what it's trying to do. My feeling is that this algorithm is probably badly designed for matlab.
In particular, the
mod(floor(x*1e15, L)) + 1
with L = 65536 looks like a poor attempt at manipulating floating point numbers at the bit level. There are faster ways of manipulating bits. The + 1 is also puzzling, without it you get numbers that fit into a uint16, with it 99.9985% of the possible numbers fit on 16 bits, and one number, 65536, requires 17 bits.

Accedi per commentare.

Risposte (0)

Richiesto:

il 25 Giu 2019

Commentato:

il 26 Giu 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by