Generating a random vector of a given norm in Matlab

423 Views Asked by At

I need to create a random vector $v$ of size $n$ with the condition that $\|v\|_1 = 10^{-8}$. I was thinking of creating it like v = rand(n, 1) * 10e-8, but it does not seem to be robust, especially with large $n$s.

Is there a common way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

If it's really the $\|\|_1$ you are thinking about, you have to divide aby the seum of coordinates :

 n=4;
 v=rand(n,1);
 v=(v/sum(v))*1e-8

BUT, doing that, you have only positive coordiantes. It would be better to consider ;

 n=4;
 v=rand(n,1)-0.5;
 v=(v/sum(abs(v)))*1e-8

(please note the $abs(...)$).

Remark : you can also use norm(v,1).