To Norbert Marwan,
The aim is fitting a linear line from the divergence curve so the elements of tlinear vector correspond to x-axis of divergence curve(d parameter), as the result this vector musn't exceed d vector. You can look at polyfit command. And if you think about before giving 2 points for rating, i will be glad because i studied a lot and controlled over and over while writing this code and there isn't any big error.
Primarily you can try a maximum iteration number whatever. And then you look your divergence curve (d parameter) on the graph. If you see a linear region in your divergence curve, you can use x axis vector that your divergence curve is linear for calculate largest lyapunov exponent. the maximum iteration and the linear region(tlinear vector) depend on your time series data.You can learn more information from Rosenstein's "A practical method for calculating largest Lyapunov exponents from small data sets" article.