% HW1: complete this Matlab code to iterate a map on [0,1].    barnett 9/13/07

% Here's how to define a function: eg
%   f = @(x) x.*x;                      note .* not * needed since elementwise
% defines the function f(x)=x^2

% Define a map in the logistic family. Put your code here ...




% ... and now to use the map:
N = 200;                   % number of iterations
x = zeros(1, N+1);         % 1-by-(N+1) sized list to store the history of x
x(1) = 0.1;                % put starting value in first element of list

% Now write a loop of some kind to fill the rest of the x array up to x(N)
% ...



% Now comes plotting code that you don't need to change.
% If you filled x correctly then it will produce nice graphs ---------------

% graph function then add cobweb plot
xx = 0:0.004:1;
figure; plot(xx, f(xx), 'k-'); xlabel x; ylabel('f(x)'); title('cobweb plot');
axis([0 1 0 1]); hold on; plot([0 1], [0 1], 'g-');
for n=1:N
  plot([x(n) x(n) x(n+1)], [x(n) x(n+1) x(n+1)], '-');
  plot(x(n), x(n+1), '.', 'markersize', 10);
end

% plot iteration x_n vs n
figure; plot(0:N, x, '.-', 'markersize', 10); xlabel n; ylabel('x_n');
axis([0 N 0 1]); title('iteration history');

% print out the graphs and attach to your HW1

