clear all;
close all;
epsilon=0.00001;
Delta_t=10.0;
t=0:Delta_t:2.0/epsilon;
%Preallocating memory
x=zeros(size(t));
x(1)=epsilon;
for n=1:length(t)-1
x(n+1)=Findxnplus1(Delta_t,x(n));
end
plot(t,x,’ko-‘,’linewidth’,3,’Markersize’,10);
axis([0 2/epsilon -0.1 1.1])
xlabel(‘t’,’Fontsize’,14);ylabel(‘x’,’Fontsize’,14);
function p=Findxnplus1(Delta_t,xn)
%initial guess value of p
p=xn;
gp=p-Delta_t*(p^2-p^3)-xn;
dgdp=1-Delta_t*(2*p-3*p^2);
while abs(gp)>1.0e-15
p=p-gp/dgdp;
gp=p-Delta_t*(p^2-p^3)-xn;
dgdp=1-Delta_t*(2*p-3*p^2);
end
end