% This script file runs the "Rates of Convergence" experiment on Page 49. % In class we said that the size of the derivative at the fixed point % determines how quickly the orbit converges, and here we test that. % % The functions are labeled as Fa, Fb, ..., Fi, Fj as on page 49. Fa=inline('x.^2+0.25'); Fb=inline('x.^2'); Fc=inline('x.^2-0.24'); Fd=inline('x.^2-0.75'); Fe=inline('0.4.*x.*(1-x)'); Ff=inline('x.*(1-x)'); Fg=inline('1.6.*x.*(1-x)'); Fh=inline('2.*x.*(1-x)'); Fi=inline('2.4.*x.*(1-x)'); Fj=inline('3.*x.*(1-x)'); % % CHANGE THESE DEPENDING ON WHAT GROUP YOU'RE USING (the ones showing are % for the first grouping, found analytically). fixedpts=[1/2,0,-0.2,-1/2]; %The procedure is to begin with x=0.2 and iterate until the function %reaches a fixed point (actually, we will measure the distance between two %iterates to see if it is very very small). x=0.2; MaxIterates=100000; %Bail out if we do too many iterations SmallNumber=10^(-5); %****************************************************************** % This section just for fun- Get cobweb diagrams for the first 4 % xa=-1;xb=1; figure(1) subplot(2,2,1); cobweb(Fa,x,10,xa,xb); subplot(2,2,2); cobweb(Fb,x,10,xa,xb); subplot(2,2,3); cobweb(Fc,x,10,xa,xb); subplot(2,2,4); cobweb(Fd,x,10,xa,xb); % %************End of graphics section******************************** for j=1:MaxIterates x=Fd(x); %YOU WILL NEED TO CHANGE THE FUNCTION NAME HERE Err1=abs(fixedpts(4)-x); %CHANGE FIXED POINT HERE if necessary if Err1