1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2019 - Samuel GOUGEON
4 // This file is hereby licensed under the terms of the GNU GPL v2.0,
5 // pursuant to article 5.3.4 of the CeCILL v.2.1.
6 // This file was originally licensed under the terms of the CeCILL v2.1,
7 // and continues to be available under such terms.
8 // For more information, see the COPYING file which you should have received
9 // along with this program.
11 function u = prbs_a(n, nc, ic)
12 // n : number of points
13 // nc : number of state changes
14 // ic : indices of state changes
20 if type(n)<>1 | n==[] | ~isreal(n,0) | or(n<>round(n)) then
21 msg = _("%s: Argument #%d: Decimal integer expected.\n")
22 error(msprintf(msg, fname, 1))
26 msg = _("%s: Argument #%d: Must be >= %d.\n")
27 error(msprintf(msg, fname, 1, 0))
35 if ~isdef("ic","l") | ic==[] then
36 u = grand(1,n-1,"unf",0,1);
40 if type(ic)<>1 | ic==[] | ~isreal(ic,0) then
41 msg = _("%s: Argument #%d: Decimal integer expected.\n")
42 error(msprintf(msg, fname, 1))
44 if min(ic) < 1 | max(ic) >= n then
45 msg = _("%s: Argument #%d: Must be in the interval %s.\n")
46 error(msprintf(msg, fname, 3, msprintf("[1, %d[", n)))
49 ic = gsort(ic,"g","i");
54 msg = _("%s: The number of switches can''t be ≥ %d = number of points.\n")
55 error(msprintf(msg, fname, n))
58 msg = _("%s: Argument #%d: Must be >= %d.\n")
59 error(msprintf(msg, fname, 2, 0))
73 u = u*sign(grand(1,1,"unf",-1,1)); // randomize the initial state