%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Math 3520: Differential Equations and Dynamical Systems % Fixed-point iteration and discrete dynamical systems %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Iterate to find the fixed point for f(x)=cos(x) formal long; % show 15 digits to observe convergence x=0.1; % x_0, initial value anywhere in R while(1) % Use Ctrl-C to terminate x=cos(x) % x_{n+1} from x_{n} pause(0.1); % enough time to see the result end %%% 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 %% Cobweb graph for cos(x) from x0=0.2; F = @(x) cos(x); [X,Y]=cobweb(F, 0.2, 10); figure; % New plot t=0:0.01:1; plot(t,t); % line (x,y)=(t,t), 0