how_many_plot = input('ile punktow rysowac: ');
how_many_use = input('ile punktow liczyc: ');
r = input('podaj r [parametr logistyczny]: ');
ociupina = 0.00000001;

gset nokey

traj1 = zeros(1,how_many_use);
traj2 = zeros(1,how_many_use);
traj1(1) = rand; % losujemy punkt od 0 do 1
traj2(1) = traj1(1) + ociupina;

for i=2:how_many_use
	traj1(i) = iteracja(r, traj1(i-1));
  traj2(i) = iteracja(r, traj2(i-1));
endfor

%multiplot(2,2);

subplot(2,2,1)
clearplot
axis([0, how_many_plot, 0, 1])
plot(traj1(1:how_many_plot),'-+')
hold on
plot(traj2(1:how_many_plot),'-+b')

new_traj = zeros(2,2*how_many_plot-2);
new_traj(1,1) = traj1(1);
new_traj(2,1) = 0.;
new_traj(1,2) = traj1(1);
new_traj(2,2) = traj1(2);
for i=2:how_many_plot-1
	new_traj(1,2*i-1) = traj1(i);
  new_traj(2,2*i-1) = traj1(i);
  new_traj(1,2*i) = traj1(i);
  new_traj(2,2*i) = traj1(i+1);
endfor

subplot(2,2,2);
clearplot
axis([0, 1, 0, 1])
x = linspace(0.,1.,201);
plot(x,iteracja(r,x),'r');
hold on;
plot(new_traj(1,:),new_traj(2,:),'-b');
hold off


subplot(2,2,3);
clearplot
axis([0, how_many_plot, -1, 1])
plot(traj1(1:how_many_plot)-traj2(1:how_many_plot));


nr_of_bins = 200;
histo = zeros(1,nr_of_bins);
for j = 1:how_many_use
  indeks = floor(nr_of_bins * traj1(j))+1;
  histo(indeks) += 1;
endfor

subplot(2,2,4);
clearplot
axis([0, 1, 0, floor(1.1 * max(histo))])
x = linspace(0.,1.,nr_of_bins);
plot(x,histo,'Lr');
