1
## Copyright (C) 1996-2015 Piotr Held
3
## This file is part of Octave.
5
## Octave is free software; you can redistribute it and/or
6
## modify it under the terms of the GNU General Public
7
## License as published by the Free Software Foundation;
8
## either version 3 of the License, or (at your option) any
11
## Octave is distributed in the hope that it will be useful,
12
## but WITHOUT ANY WARRANTY; without even the implied
13
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
## PURPOSE. See the GNU General Public License for more
17
## You should have received a copy of the GNU General Public
18
## License along with Octave; see the file COPYING. If not,
19
## see <http://www.gnu.org/licenses/>.
22
## @deftypefn{Function File} {@var{output} =} lyap_r (@var{X})
23
## @deftypefnx{Function File} {@var{output} =} lyap_r (@var{X}, @var{paramName}, @var{paramValue}, @dots{})
25
## Estimates the largest Lyapunov exponent of a given scalar data set using
26
## the algorithm described by Resentein et al. on the TISEAN refernce page:
28
## http://www.mpipks-dresden.mpg.de/~tisean/Tisean_3.0.1/docs/chaospaper/citation.html
34
## Must be realvector. The output will be alligned with the input.
37
## @strong{Parameters}
41
## Embedding dimension to use [default = 2].
43
## Delay used [default = 1].
45
## Window around the reference point which should be omitted [default = 0].
47
## Minimum length scale for the neighborhood search [default = 1e-3].
49
## Number of iterations in time [default = 10].
56
## Gives information about the current epsilon while performing computation.
61
## Alligned with input. If input was a column vector than output contains two
62
## columns. The first contains the iteration number and
63
## the second contains the logarithm of the stretching factor for that
66
## @seealso{demo lyap_r, lyap_k, lyap_spec}
68
## @strong{Algorithms}
70
## The algorithms for this functions have been taken from the TISEAN package.
73
## Author: Piotr Held <pjheld@gmail.com>.
74
## This function is based on lyap_r of TISEAN 3.0.1
75
## https://github.com/heggus/Tisean"
77
function output = lyap_r (X, varargin)
79
# Initial input validation
84
if ((isvector (X) == false) || (isreal(X) == false))
85
error ('Octave:invalid-input-arg', "X must be a realvector");
97
p.FunctionName = "lyap_r";
99
isPositiveIntScalar = @(x) isreal(x) && isscalar (x) && ...
100
(x > 0) && (x-round(x) == 0);
101
isNonNegativeIntScalar = @(x) isPositiveIntScalar (x) || (length (x) == 1 ...
103
isPositiveScalar = @(x) isreal(x) && isscalar (x) && (x > 0);
105
p.addParamValue ("m", embdim, isPositiveIntScalar);
106
p.addParamValue ("d", delay, isPositiveIntScalar);
107
p.addParamValue ("t", mindist, isNonNegativeIntScalar);
108
p.addParamValue ("r", eps0, isPositiveScalar);
109
p.addParamValue ("s", steps, isPositiveIntScalar);
110
p.addSwitch ("verbose");
112
p.parse (varargin{:});
115
embdim = p.Results.m;
117
mindist = p.Results.t;
119
epsset = !ismember ('r', p.UsingDefaults);
121
verbose = p.Results.verbose;
123
# Correct X to always have more rows than columns
125
if (rows (X) < columns (X))
130
output = __lyap_r__ (X, embdim, delay, mindist, eps0, epsset, steps,...
141
%! in = sin (idx ./ 360) + cos (idx ./ 180);
147
%! res = lyap_r (in, 'm', i, 'd', 6, 's',400,'t',200);
148
%! plot (res(:,1),res(:,2),'r');
151
%! xlabel ("t [flow samples]");
152
%! ylabel ("S(eps, embed, t)");
154
%!###############################################################
158
%! lyap_r_res = [0 -2.983802;1 -2.980538;2 -2.962341;3 -2.931719;4 -2.891934;5 -2.846183;6 -2.797121;7 -2.74671;8 -2.69629;9 -2.646711;10 -2.598477];
159
%! in = sin((1:1000).'./360);
160
%! res = lyap_r (in, 'm',4 ,'d',6,'s',10,'t',100);
161
%! assert (res, lyap_r_res, -1e-6);
163
%% Check if transposed output works correctly
165
%! res1 = lyap_r(1:100);
166
%! res2 = lyap_r((1:100).');
167
%! assert(res1.',res2);
169
%!error <ranges> lyap_r (1)
170
%% Check if program does not run forever
171
%!error <too large> lyap_r (1:12)