A_vector=[0.9 1.07 1.15 1.35 1.46 1.5];
behaviors=["Periodic orbit","Two-cycle","Chaos","Periodic Orbit","Four-cycle","Chaos"];
f=@(t,y)pendForceDamp(t,y,b,A,omega);
fEvent=@(t,y)pendulumEvent(t,y,omega);
options=odeset('Events',fEvent,'RelTol',1e-8,'AbsTol',1e-8);
[t,y,te,ye]=ode45(f,tSpan,y0,options);
spot=find(t>tTransient,1,'first');
% Throw away a transient from the events time series
spot=find(te>tTransient,1,'first');
plot(y(:,1),y(:,2),ye(:,1),ye(:,2),'o')
title(sprintf('$A=%0.2f$: %s',A),behaviors(k))
xlabel('$\theta$');ylabel('$\frac{d\theta}{dt}$')
plot(mod(ye(:,1),2*pi),ye(:,2),'o')
axis([0 2*pi min(y(:,2)) max(y(:,2))])
title(sprintf('$A=%0.2f$: %s',A),behaviors(k))
xlabel('$\theta$');ylabel('$\frac{d\theta}{dt}$')
y0=y(end,:); % use the final solution as the new initial condtion
A_vector=linspace(a0,a1,nA);
f=@(t,y)pendForceDamp(t,y,b,A,omega);
fEvent=@(t,y)pendulumEvent(t,y,omega);
options=odeset('Events',fEvent,'RelTol',1e-8,'AbsTol',1e-8);
[~,~,te,ye]=ode45(f,tSpan,y0,options);
% Throw away a transient from the events time series
spot=find(te>tTransient,1,'first');
plot(ones(length(ye),1)*A,ye(:,2),'b.')
xlabel('$A$');ylabel('$\frac{d\theta}{dt}$')
function dydt=pendForceDamp(t,y,b,A,omega)
dydt(2) = -b* y(2) - sin(y(1)) + A*sin(omega*t);
function [value, isterminal,direction]=pendulumEvent(t,~,omega)