Find first row where the first 10 elements of that row are unique from each other
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am plotting the Ricker map and trying to find at what point chaos in the map occurs. I have been trying to do so by searching for the row in matrix 'x' where the first 10 values are unique (non-repeating and converging to chaos). Can anyone help me in how to do this, or explain a better method.
Ntrans = 1024; % Set a large value to eliminate transients later
NT = 256; % Total number of iterations
r_vec = linspace(0,4,1024); % Set control parameter in an array using linspace
x_init = 0.15; % Initial Population
c = zeros(1024,257);
% Setting array index K equal to # of elements in r_vec
% Assigning r to the element of r_vec each cycle through k
% Assigning x0 to value of initial population
for k = 1:length(r_vec)
r = r_vec(k);
x0 = x_init;
% Iterate the map Ntrans times to reach asymptotic solution.
for jj = 1:Ntrans
x0 = x0*exp(r*(1-x0));
end
% Assigning first entry in array to x0
x(k,1) = x0;
% Iterate the map NT times
for j = 1:NT
x(k,j+1) = x(k,j)*exp(r*(1-x(k,j)));
end
end
figure(1)
set(gcf,'name','Bifurcation diagram','numbertitle','off')
plot(r_vec,x,'r.','Markersize',1)
grid on; box on, xlabel('r'); ylabel('lim_{n\rightarrow\infty} x_n')
title('Bifurcation diagram of the Ricker map')
xticks(0:0.5:4), yticks(0:0.5:5)
axis([0 4 0 5])
댓글 수: 0
답변 (1개)
Walter Roberson
2023년 11월 23일
row_has_10_unique = all(diff(sort(x(:,1:10)),2) > 0,2);
댓글 수: 6
Walter Roberson
2023년 11월 23일
row_has_10_unique = all(diff(sort(x(:,1:10)),[],2) > 0,2);
I tend to forget that the dimension is the third parameter to diff.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!