From 6b237eb6c2819273d502c35058ca862730249bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 6 Sep 2013 16:49:40 +0200 Subject: [PATCH] =?UTF-8?q?Added=20method=20dynTimeIndex::mpower=20->=20le?= =?UTF-8?q?ad-lag=20operators=20=C3=A0=20la=20G-M=20;-).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This method can be used to apply the lead and lag methods an arbitrary number of times to a dynSeries object. For instance, if ts is a dynSeries object, and if we define >> B = dynTimeIndex()-1; >> F = dynTimeIndex()+1; B and F can be used as lag and lead operators and the following syntax: >> us = ts(F^2); is equivalent to >> us = ts.lead(2) or >> us = ts.lead.lead --- matlab/@dynTimeIndex/mpower.m | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 matlab/@dynTimeIndex/mpower.m diff --git a/matlab/@dynTimeIndex/mpower.m b/matlab/@dynTimeIndex/mpower.m new file mode 100644 index 000000000..81cfb3cfd --- /dev/null +++ b/matlab/@dynTimeIndex/mpower.m @@ -0,0 +1,74 @@ +function C = mpower(A,B) % --*-- Unitary tests --*-- + +% C = mpower(A,B) +% +% Overloads binary mpower operator (^). +% +% INPUTS : +% * A, dynTimeIndex object. +% * B, integer scalar. +% +% OUTPUTS : +% * C, dynTimeIndex object. +% +% EXAMPLE 1 : +% +% >> B = dynTimeIndex()-1; +% >> B +% B = +% >> B^4 +% ans = +% >> +% +% EXAMPLE 2 : +% This method can be used to apply the lead and lag methods an arbitrary number of times to a dynSeries object. For instance, if +% ts is a dynSeries object, and if we define +% +% >> B = dynTimeIndex()-1; +% >> F = dynTimeIndex()+1; +% +% B and F can be used as lag and lead operators and the following syntax: +% +% >> us = ts(F^2); +% +% is equivalent to +% +% >> us = ts.lead(2) +% +% or +% +% >> us = ts.lead.lead +% + +% Copyright (C) 2013 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +if ~(isa(A,'dynTimeIndex') || isint(B)) + error(['dynTimeIndex::mpower: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be a dynTimeIndex object and an integer!']) +end + +C = struct(); +C.index = A.index*B; +C = class(C,'dynTimeIndex'); + +%@test:1 +%$ a = dynTimeIndex()+1; +%$ b = a^2; +%$ t(1) = isa(b,'dynTimeIndex'); +%$ t(2) = isequal(b.index,int8(2)); +%$ T = all(t); +%@eof:1 \ No newline at end of file