
format compact
format long

%mysystem='lorenzmio'
%mysystem='Rossler'

if(exist('mysystem')==0)
 error('Use mysystem=''lorenzmio'' or mysystem=''Rossler''')
end

switch mysystem
 case 'lorenzmio'
  delta=1e-4; 
  ICx=-0.6895;
  ICy=-0.0560;
  ICz=19.3245;
  tfin=30;
  ti=1000;
  tf=1600;

 case 'Rossler'
  delta=1e-4; 
  ICx=5;
  ICy=-5;
  ICz=0.1;
  tfin=300;
  ti=2700;
  tf=3600;

 otherwise
  error('Use mysystem=''lorenzmio'' or mysystem=''Rossler''')
end

IC1=[ICx, ICy, ICz]
IC2=[ICx+1*delta,ICy+delta,ICz+delta]
diffICs=IC1-IC2;

[T1,Y1]=threeplot(mysystem,ICx,ICy,ICz,0,tfin);
[T2,Y2]=threeplot(mysystem,ICx+1*delta,ICy+delta,ICz+delta,0,tfin);

[~,ti2]=max(T2>T1(ti));ti2=ti2-1;

 figure(11)
 clf
 plot3(Y1(:,1),Y1(:,2),Y1(:,3),'LineWidth',0.2)
 set(gca,'FontSize',16)
 xlabel('x')
 ylabel('y')
 zlabel('z')
 rotate3d
 axis tight
 view([40,40])
 set(gca,'FontSize',16)
 title(['Unperturbed orbit, full run: 0<t<',num2str(T1(end))])


 figure(1)
 clf
 plot(T1(ti),Y1(ti:ti,1),'go','MarkerSize',6,'LineWidth',5)
 hold on
 plot(T1,Y1(:,1),T2,Y2(:,1),'r','LineWidth',2)
 set(gca,'FontSize',16)
 xlabel('t')
 ylabel('x(t)')
 set(gca,'FontSize',16)
 hold off
 title(['Both orbits, full run: 0<t<',num2str(T1(end))])
 
 figure(2)
 clf
 set(gca,'FontSize',16)
 plot3(Y1(ti:ti,1),Y1(ti:ti,2),Y1(ti:ti,3),'go','MarkerSize',6,'LineWidth',5)
 hold on
 plot3(Y1(ti:tf,1),Y1(ti:tf,2),Y1(ti:tf,3),'LineWidth',2)
 hold on
 plot3(Y2(ti2:tf,1),Y2(ti2:tf,2),Y2(ti2:tf,3),'r','LineWidth',2)
 set(gca,'FontSize',16)
 xlabel('x')
 ylabel('y')
 zlabel('z')
 rotate3d
 hold off
 axis tight
 view([40,40])
 set(gca,'FontSize',16)
 title(['Both orbits, partial run:',num2str(T1(ti)),'<t<',num2str(T1(end))])

 figure(11)
