% CLASS4OCT.TXT Transcript of what was done in class on Monday 4 Oct for % Math 310. % demonstrate Newton's method to solve x = cos(x), which means using a % fixed point iteration with g(x) = x - (x-cos(x)) / (1+sin(x)) % because f(x) = x - cos(x) format long p=0.5 for n = 1:7, p = p - (p-cos(p)) / (1+sin(p)), end % compare to a "naive" fixed point iteration which also solves x = cos(x) p=0.5 for n=1:15, p = cos(p), end % some equivalent fixed point iterations which apparently *do not* converge p=0.5 for n=1:5, p = acos(p), end p=0.739 for n=1:10, p = acos(p), end p=0.5 for n=1:5, p = (p/cos(p))+p-1, end % and finally one that converges fast p=0.5 for n=1:10, p = sqrt(cos(p))-sqrt(p)+p, end % a picture showing why the last iteration converges; note that the slope at % the point x=p, y=p is small figure x=0.5:.001:1; plot(x,x,x,sqrt(cos(x))-sqrt(x)+x), axis([0.5 1 0.7 0.8]) % and a picture showing why Newton's method is such a good fixed point iteration figure x=0.5:.001:1; plot(x,x,x,x-(x-cos(x))./(1+sin(x))), axis([0.5 1 0.73 0.745])