A Matlab code to generate random numbers following multi-dimensional Cauchy distributions is provided here.
The following publication contains mathematical details of the method and the code, which should be cited whenever relevant.
cauchyn.m
function [x, r] = cauchyn(t, y, T, m, n) % x - n-dimensional cauchy random numbers % r - norm of x % [t, y] - lookup table % T - Cauchy parameter % m - number of random numbers % n - random number dimension u = rand(m,1); c = find(y < 0); if isempty(c) y1 = y; t1 = t; else y1 = y(c(size(c,1))+1:size(y,1),:); t1 = t(c(size(c,1))+1:size(t,1),:); end theta = interp1(y1, t1, u); r = T * tan(theta); x = randn(m,n); x = repmat(r, [1,size(x,2)]) .* x ./ repmat(sqrt(sum(x .* x, 2)), [1,size(x, 2)]);
cauchyn_gen.m
function [t,y] = cauchyn_gen(n, s) % n - dimension % s - size of lookup table [t,y] = ode45(@cauchyn_dydt, [pi/(2*s):pi/(2*s):pi/2], 0, 'AbsTol', n);
cauchyn_dydt.m
function dydt = cauchyn_dydt(t, y, n) dydt = sin(t)^(n-1);
[t, y] = cauchyn_gen(n, s)
[x, r] = cauchyn(t, y, T, m, n)