1 function x_hat = perturb(x, epsilon)
3 % Generate a perturbed copy of ``x``, that is, a vector (or matrix)
4 % of the form ``x + dx`` where ``dx`` has same dimensions as x and
9 % ``x`` -- The vector or matrix to perturb.
11 % ``epsilon`` -- An upper bound for the entries of ``dx``.
15 % ``x_hat`` -- A perturbed copy of ``x``; ``x_hat == x + dx``.
18 % If no epsilon was given, make something up.
23 % This creates a vector or matrix whose entries lie in [-1,1].
24 dx = 2*rand(size(x)) - 1;
26 % First normalize delta, using the infinity norm for speed (since
28 dx = dx / norm(dx, 'inf');
30 % Now scale it so that its largest entry is
31 dx = dx * norm(x,'inf') * epsilon;