%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         8. practice         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Nonlinear dynamics systems  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         2016.11.09.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Spiderweb diagram of Logistic mapping %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Parameters:
figure;
kezdet=0.2;
iteraciok=500;

for mu=3.4:0.01:4%0.1:0.05:4 %default
egyenes=linspace(0,1,iteraciok);
gorbe=mu*egyenes.*(1-egyenes);

subplot(3,1,1);
%draw the x=y line and the function
plot(egyenes,gorbe, egyenes,egyenes);
hold on;

%do the iterations
Population=zeros(iteraciok,1);
Population(1)=kezdet;

for i=1:(iteraciok-1)
    Population(i+1)=;
end

% spiderweb diagram:
%{
%from the beginning:
    plot([Population(1),Population(2)],[Population(2),Population(2)],'red');
    plot([Population(1),Population(1)],[0,Population(2)],'red');
for i=2:(iteraciok-1)
    %}
for i=100:(iteraciok-1) %only the end after stabilisation
    plot([Population(i),Population(i+1)],[Population(i+1),Population(i+1)],'red');
    plot([Population(i),Population(i)],[Population(i),Population(i+1)],'red');
end
title(['mu=', num2str(mu)]);
hold off;

subplot(3,1,2);
plot(Population);
ylim([0,1]);
xlabel('iteration');
ylabel('population');

%
%Ljapunov exponent:
Population_derivalt =;
Ljapunov =;
[mu, Ljapunov] %write to the consol
subplot(3,1,3);
plot(mu,Ljapunov, 'r.', 'MarkerSize', 10);
hold on;
xlabel('mu');
xlim([0 4]);
ylabel('Ljapunov exponent');
ylim([-3,1]);
%}

%waitforbuttonpress;
pause(0.1);
end;