Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions algorithms/arithmetic_analysis/fixed_point_iter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function fpi(f,a, b, x0, N)

% generate the cobweb diagram associated with
% the iteration: x_{n+1}=f(x_n).
% N is the number of iterates, and
% (a,b) is the interval
% x0 is the initial point.
% plot y=f(x)

x=a:.01:b;
y=f(x);
figure
hold on;
title('fixed point iteration')
plot(x,y,'k'); % plot the function
plot(x,x,'r'); % plot straight line
x(1)=x0; % plot orbit starting at x0
for i=1:N
x(i+1)=f(x(i));
if i==1
line([x(i),x(i)],[0,x(i+1)]);
else
line([x(i),x(i)],[x(i),x(i+1)]);
end
pause
line([x(i),x(i+1)],[x(i+1),x(i+1)]);
pause
end
hold off;