diff options
-rw-r--r-- | macros/arma_rnd.sci | 75 |
1 files changed, 30 insertions, 45 deletions
diff --git a/macros/arma_rnd.sci b/macros/arma_rnd.sci index 5e9ca12..fb428cc 100644 --- a/macros/arma_rnd.sci +++ b/macros/arma_rnd.sci @@ -1,27 +1,20 @@ +function x = arma_rnd (a, b, v, t, n) //Return a simulation of the ARMA model. - -//Calling Sequence +//Calling Sequence: //arma_rnd (a, b, v, t, n) //arma_rnd (a, b, v, t) - -//Parameters -//a: vector -//b: vector +//Parameters: +//a: Real vector +//b: Real vector //v: Variance //t: Length of output vector //n: Number of dummy x(i) used for initialization - -//Description -//This is an Octave function. -//The ARMA model is defined by -// -//x(n) = a(1) * x(n-1) + … + a(k) * x(n-k) -// + e(n) + b(1) * e(n-1) + … + b(l) * e(n-l) +//Description: +//The ARMA model is defined by x(n) = a(1) * x(n-1) + … + a(k) * x(n-k) + e(n) + b(1) * e(n-1) + … + b(l) * e(n-l) //in which k is the length of vector a, l is the length of vector b and e is Gaussian white noise with variance v. The function returns a vector of length t. -// -//The optional parameter n gives the number of dummy x(i) used for initialization, i.e., a sequence of length t+n is generated and x(n+1:t+n) is returned. If n is omitted, n = 100 is used. - -//Examples +//The optional parameter n gives the number of dummy x(i) used for initialization, i.e., a sequence of length t+n is generated and x(n+1:t+n) is returned. +//If n is omitted, n = 100 is used. +//Examples: //a = [1 2 3 4 5]; //b = [7 8 9 10 11]; //v = 10; @@ -30,36 +23,13 @@ //arma_rnd (a, b, v, t, n) //Output : // ans = -// // 61400.907 // 158177.11 // 407440.29 // 1049604. // 2703841.3 - -//function res = arma_rnd (a, b, v, t, n) -//funcprot(0); -//lhs = argn(1) -//rhs = argn(2) -//if (rhs < 5 | rhs > 6) -//error("Wrong number of input arguments.") -//end -// -//select(rhs) -// -// case 5 then -// res = callOctave("arma_rnd",a, b, v, t) -// -// case 6 then -// res = callOctave("arma_rnd",a, b, v, t, n) -// -// end -//endfunction - -function x = arma_rnd (a, b, v, t, n) - - funcprot(); + funcprot(0); [nargout,nargin] = argn() ; if (nargin == 4) @@ -69,7 +39,7 @@ function x = arma_rnd (a, b, v, t, n) error ("arma_rnd: N must be a scalar"); end else - error("arma_rnd: invalid input"); + error("Wrong number of input arguments."); end if ((min (size (a)) > 1) | (min (size (b)) > 1)) @@ -85,16 +55,31 @@ function x = arma_rnd (a, b, v, t, n) a = matrix (a, ar, 1); b = matrix (b, br, 1); - - // Apply our notational convention. a = [1; -a]; b = [1; b]; n = min (n, ar + br); - e = sqrt (v) * rand(t + n, 1); x = filter (b, a, e); x = x(n + 1 : t + n); endfunction + +//input validation: +//a = [1, 2, 3, 4]; +//b = [5, 6, 7]; +//assert_checkerror("arma_rnd()", "Wrong number of input arguments."); +//assert_checkerror("arma_rnd(1, 2, 3, 4, 5, 6)", "Wrong number of input arguments."); +//assert_checkerror("arma_rnd(a, b, 5, 2, a);", "arma_rnd: N must be a scalar"); +//assert_checkerror("arma_rnd(a, b, 5, a);", "arma_rnd: T must be a scalar"); +//assert_checkerror("arma_rnd([1 2; 3 4], [5 6; 7 8], 5, 1);", "arma_rnd: A and B must not be matrices"); + +//tests: +//NOTE: The output of arma_rnd is supposed to be random, so we cannot expect the same output for equivalent input. +//a = [1, 2, 3, 4]; +//b = [5, 6, 7, 8]; +//assert_checkequal(size(arma_rnd(a, b, 5, 1)), [1 1]); +//assert_checkequal(size(arma_rnd(a, b, 5, 2, 100)), [2 1]); +//assert_checkequal(size(arma_rnd(a', b', 1, 10, 50)), [10 1]); +//assert_checkequal(size(arma_rnd(a, b', 1, 4, 5)), [4 1]); |