Animating an Iteration m file
1 view (last 30 days)
Show older comments
Would it be possible to animate the m-file below of the quadratic iterator or to create a pause between successive iterations to then save as a gif and use in a power point presentation. Below is the code and I have r2013a matlab and 2013 powerpoint
function L=logis(a,x0,max,tol,g)
% LOGISTIC Fixed-point iteration for the logistic equation.
%
% Examples: (1) logistic(3.3,0.1,20,0.01,1);
%
% or (2) x=logistic(3.63,0.1,2000,0.01,0);
%
% LOGISTIC(A,X0,MAX,TOL,G) performs fixed point iteration of
% the form x_n+1=G(x_n) with graphical output between x=0 and x=1
% for the logistic equation p=Ap(1-p).
%
% X0 is the initial value of x.
% MAX is the maximum number of iterations allowed.
% TOL (optional - default = 0) is a tolerance value used
% to stop the iteration.
% G (optional - default = 0) turns the graphics on or off.
%
% Christian C. Beardah 1993-94
if (nargin < 3 | nargin > 5) % Check number of input parameters.
error('Incorrect number of function parameters');
end;
if nargin==3,
tol=0;
g=0;
end;
if nargin==4,
g=0;
end;
vx(1)=x0;
if g~=0,
c=1/80; % Increment and range for plots.
x=-100*c:c:1.575+100*c;
plot(x,a*x.*(1-x),'g');
hold on;
xlabel('x values');
plot([-100*c,1.575+100*c],[0,0],'m');
plot(x,x,'r');
plot([x0,x0],[0,a*x0.*(1-x0)]);
end;
for i=1:max-1;
xn=a*x0.*(1-x0);
vx(i+1)=xn;
if g~=0,
plot([x0,xn],[a*x0.*(1-x0),a*x0.*(1-x0)],'b');
plot([xn,xn],[xn,a*xn.*(1-xn)],'b');
end;
if abs(xn-x0)<tol,
break;
end;
x0=xn;
end;
if g~=0,
hold off;
pause;
close;
for j=1:i+1;
fprintf('i= %2g x_i= %8.6f\n',j,vx(j))
end;
end;
L=vx;
return;
0 Comments
Answers (0)
See Also
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!