%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Math 3520: Differential Equations and Dynamical Systems % Function to compute Cobweb graph coordinates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [X,Y] = cobweb(F,X0,steps) % Input % F = function handle, computes X(n+1) from X(n) % X0 = initial value X(1) % steps = number of visits to X=Y line (e.g., 10) % Output % X,Y = coordinates to plot a cobweb starting at X0 X(1) = X0; % Initial value for iteration Y(1) = 0; % Initial cobweb point is on X-axis for j=2:2:2*steps % roundtrip to X=Y takes 2 steps X(j) = X(j-1); % up/down to the graph of F Y(j) = F(X(j)); % X(j+1) = Y(j); % left/right to X=Y line Y(j+1) = Y(j); % end end