Octonacci[k_]:=Module[{octo,i},
octo=Table[0,{i,1,k}];
octo[[1]]=1;
octo[[2]]=2;
Do[ octo[[i]]=octo[[i-2]]+2*octo[[i-1]],{i,3,k}];
octo];

Octonacci[10]

Clear[liens,ppts,RawHamFlux];

liens=Import["liensPBC6v2.dat"];
ppts=Import["PtsPBC6v2.dat"];
l=Length[liens];
ll=Length[ppts];

cut=0.5;


RawHamFlux=Reap[Do[{rat=N[169*Sqrt[2]];
dx=ppts[[liens[[m,1]],1]]-ppts[[liens[[m,2]],1]];
dy=ppts[[liens[[m,1]],2]]-ppts[[liens[[m,2]],2]];

If[(liens[[m,1]]<liens[[m,2]])&&(Abs[dy]<cut)&&(Abs[dx]<cut),(*Print["Cond  "," ",dx," ",dy," ",liens[[m,1]]," ",liens[[m,2]]];*)
Sow[{{liens[[m,1]],liens[[m,2]]},-Exp[I*Pi*Phi*rat*rat*((ppts[[liens[[m,2]]]])[[2]]-(ppts[[liens[[m,1]]]])[[2]])*((ppts[[liens[[m,2]]]])[[1]]+(ppts[[liens[[m,1]]]])[[1]])]}];
Sow[{{liens[[m,2]],liens[[m,1]]},-Exp[-I*Pi*Phi*rat*rat*((ppts[[liens[[m,2]]]])[[2]]-(ppts[[liens[[m,1]]]])[[2]])*((ppts[[liens[[m,2]]]])[[1]]+(ppts[[liens[[m,1]]]])[[1]])]}];]
},{m,1,l}]][[2,1]];

tmp=Split[Sort[RawHamFlux],#1[[1]]==#2[[1]]&];
RawHamFlux=Table[tmp[[i,1,1]]->Tr[Transpose[tmp[[i]]][[2]]],{i,1,Length[tmp]}];

Fond5flux=Monitor[Reap[
For[n=1,n≤1000,n++,
rulef={Phi->n/1000.};
ham=SparseArray[RawHamFlux/.rulef];
Sow[Flatten[{n/1000,Eigenvalues[ham,1,Method->{"Arnoldi","MaxIterations"->4000}]}]]
(*,Method->{"Arnoldi","MaxIterations"->4000}]
res=Eigensystem[ham];
For[j=1,j≤ntot,j++,
If[Tr[((Abs[res[[2,j]]])^4)]<ϵ,Sow[Flatten[{f,Chop[res[[1,j]]]}]/.rulef]];
];*)

]][[2,1]],n];

Fond6flux=Monitor[Reap[
For[n=1,n≤1000,n++,
rulef={Phi->n/1000.};
ham=SparseArray[RawHamFlux/.rulef];
Sow[Flatten[{n/1000,Eigenvalues[ham,20,Method->{"Arnoldi","MaxIterations"->4000}]}]]
(*,Method->{"Arnoldi","MaxIterations"->4000}]
res=Eigensystem[ham];
For[j=1,j≤ntot,j++,
If[Tr[((Abs[res[[2,j]]])^4)]<ϵ,Sow[Flatten[{f,Chop[res[[1,j]]]}]/.rulef]];
];*)

]][[2,1]],n];

Fond5flux2=Monitor[Reap[
For[n=1,n≤1000,n++,
rulef={Phi->n/1000.};
ham=SparseArray[RawHamFlux/.rulef];
Sow[Flatten[{n/1000,Eigenvalues[ham,10,Method->{"Arnoldi","MaxIterations"->2000}]}]]
(*,Method->{"Arnoldi","MaxIterations"->4000}]
res=Eigensystem[ham];
For[j=1,j≤ntot,j++,
If[Tr[((Abs[res[[2,j]]])^4)]<ϵ,Sow[Flatten[{f,Chop[res[[1,j]]]}]/.rulef]];
];*)

]][[2,1]],n];

l1=Transpose[{Transpose[Fond5flux2][[1]],Transpose[Fond5flux2][[2]]}];

ListPlot[l1]

l1[[1]]

Clear[lneg];

l1neg=Reap[Do[Sow[{l1[[i,1]],Min[Take[Fond5flux2[[i]],{2,11}]]}],{i,1,Length[l1]}]];

ListPlot[l1neg[[2]]]

Export["fond_5.dat",N[l1]];

l1=Import["fond_5.dat"];

ll

Length[Fond5flux2[[3]]]

Fond5flux

Clear[f5];

data=Reap[Do[Sow[Min[Take[Fond5flux2[[i]],{2,11}]]],{i,1,Length[l1]}]];

ListPlot[data[[2]]]

f5=Fourier[Flatten[data[[2]]]];

dat=Flatten[data[[2]]];

ListPlot[Abs[f5]^2]

fourier[l_,n_]:=Sum[Exp[2*I*Pi*n*k/1000]*l[[k]],{k,1,1000}];

fourier[dat,1]

f5[[1]]

ListPlot[Table[{i/1000,Abs[N[fourier[dat,i]]]^ 2},{i,1,1000}]]

pics={2*Pi*0.08084,2*Pi*0.9143}

l1negnorm=Reap[Do[Sow[{i/1000,(dat[[i]]-s)/(-s)}],{i,1,1000}]];

Show[Plot[0.998363486715098` +0.0006523850176347366` Cos[0.5026548245743669` x]-0.00012043534533015776` Cos[5.717698629533424` x],{x,0.,1.}],ListPlot[l1negnorm[[2]]]]

Fit[l1negnorm[[2]][[1]],{1,Cos[2*Pi*x*0.08],Cos[2*Pi*x*0.91]},x]

Fit[l1negnorm[[2]][[1]],{1,Cos[2*Pi*x*0.08]},x]

0.9984329891873314` +0.0005916490829272354` Cos[0.5026548245743669` x]

Octonacci[10]

ratiosOcto={1/2,2/5,5/12,12/29,29/70,70/169}

ratiosOcto2={1/5,2/12,5/29,12/70,29/169}

ratiosHuit={1/8,2/8,3/8,4/8,5/8,6/8,7/8}

N[ratiosOcto]

ratiosSupOcto={2,5/2,12/5,29/12}

N[ratiosSupOcto]

Show[ListPlot[l1negnorm[[2]]],ListPlot[Table[{ratiosOcto[[i]],0.999},{i,1,4}],PlotStyle->Red],ListPlot[Table[{ratiosSupOcto[[i]],0.999},{i,1,4}],PlotStyle->Green]]

fond5=

ListPlot[Table[{ratiosOcto[[i]],0.999},{i,1,6}],PlotStyle->Red]

Show[fond5,ListPlot[Table[{ratiosOcto[[i]],0.999},{i,1,6}],PlotStyle->Red], ListPlot[{{1/N[1+Sqrt[2]],0.999},{1/N[1-Sqrt[2]],0.999}},PlotStyle->Green]]

1/(1.+Sqrt[2])

l6=Transpose[{Transpose[Fond6flux][[1]],Transpose[Fond6flux][[2]]}];

l6neg=Reap[Do[Sow[{l6[[i,1]],Min[Take[Fond6flux[[i]],{2,21}]]}],{i,1,Length[l6]}]];

ListPlot[l6]

Show[ListPlot[l6neg[[2]]],ListPlot[Table[{ratiosOcto[[i]],-3.0},{i,1,6}],PlotStyle->{PointSize[0.005],Red}],ListPlot[Table[{ratiosOcto2[[i]],-3.0},{i,1,5}],PlotStyle->{PointSize[0.005],Green}],ListPlot[Table[{ratiosHuit[[i]],-3.0},{i,1,7}],PlotStyle->{PointSize[0.005],Pink}]]