Rank: 1142 based on 116 downloads (last 30 days) and 3 files submitted
photo

Roger Stafford

E-mail

Personal Profile:

 

Watch this Author's files

 

Files Posted by Roger Stafford View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
18 Oct 2006 Adjugate (adjoint) of a Square Matrix Calculates the adjugate (adjoint) matrix for a square matrix. Author: Roger Stafford linear algebra, adjugate, adjoint, matrix, singular, cofactors 20 6
  • 4.0
4.0 | 3 ratings
24 Jan 2006 Screenshot Random Vectors with Fixed Sum Randomly and uniformly generates vectors with a specified sum and values in a specified interval. Author: Roger Stafford random, fixedsum, ndimensional, simplex, hypercube 69 11
  • 5.0
5.0 | 9 ratings
28 Dec 2005 Screenshot Random Points in an n-Dimensional Hypersphere Randomly and uniformly distributes points throughout a hypersphere. Author: Roger Stafford ndimensional, hypersphere, random, uniformlydistributed, incomplete, radius 27 13
  • 4.78571
4.8 | 14 ratings
Comments and Ratings on Roger Stafford's Files View all
Updated File Comment by Comments Rating
05 Apr 2014 Random Vectors with Fixed Sum Randomly and uniformly generates vectors with a specified sum and values in a specified interval. Author: Roger Stafford vachelard

Hi
I try to use the function, but I have a problem when I'm driving.
I have a matrix A (193.1) I would like to create a matrix (193.3) whose sum equals one line to my matrix A.
I tried the following code but I meet an error:

Rhedgefund = Y (:, 1);

cols_to_generate = 3;

for K = 1: length (Y)

    Neva (K, :) = randfixedsum (1 cols_to_generate, Y (K), -0.15, 0.15);
end

He told me:

Index EXCEEDS matrix dimensions.

Error in randfixedsum (line 95)

x = (b-a) * x (p + repmat ([0: n: n * (m-1)] n, 1)) + a; % Switches & rescale x
 
95 x = (b-a) * x (p + repmat ([0: n: n * (m-1)] n, 1)) + a; % Switches & rescale x

I do not know how to solve problem

10 Apr 2013 Random Vectors with Fixed Sum Randomly and uniformly generates vectors with a specified sum and values in a specified interval. Author: Roger Stafford shatakshi sharma

i am trying to generate 6 random nmbrs within given range and sum:
xmin=[10 10 40 35 130 125];
xmax=[125 150 250 210 325 315];
Pg=randfixedsum(1,6,200,xmin, xmax);
it is giving following error:
?? Error using ==> minus
Matrix dimensions must agree.

Error in ==> randfixedsum at 56
s1 = s - (k:-1:k-n+1); % s1 & s2 will never be negative

Error in ==> busdatas at 47
Qg=randfixedsum(30,1,total(8),xmin, xmax);

can sm1 tell wats wrong..i cnt figure it out..

18 Mar 2013 Random Points in an n-Dimensional Hypersphere Randomly and uniformly distributes points throughout a hypersphere. Author: Roger Stafford Kuan-Sung

Hi,

In AMB's code, we should generate X again before we perform Laurent's approach. Then the results from 2 approaches are similar.

Thanks,
Kuan-Sung

20 Nov 2012 Random Points in an n-Dimensional Hypersphere Randomly and uniformly distributes points throughout a hypersphere. Author: Roger Stafford AMB

Hi - This post is in reference to Laurent's comments.

Using this sample code, we see that Laurent's code substitution is faster, but the result is different from the original. Laurent's modification appears to produce data that spans a different radius than the original and is comprised of data which when viewed on the screen in a 2D projection appears more centrally clustered. The original code produces more defined boundaries.

Both ideas may have their own virtues depending on application.

m = 30000;n = 2; r = 2;
X = randn(m,n);
s2 = sum(X.^2,2);
tic
X = X.*repmat(r*(gammainc(s2/2,n/2).^(1/n))./sqrt(s2),1,n);
toc
subplot(1,2,1);plot(X(:,1),X(:,2),'r.','markersize',1);
axis equal;zoom off; zoom on;drawnow;shg;
ax = axis;

tic
X = X.*repmat(r*(rand(m,1).^(1/n))./sqrt(s2),1,n);
toc
subplot(1,2,2);plot(X(:,1),X(:,2),'r.','markersize',1);
axis equal;zoom off; zoom on;drawnow;shg;
axis(ax);

pause

m = 30000;n = 3; r = 2;
X = randn(m,n);
s2 = sum(X.^2,2);
tic
X = X.*repmat(r*(gammainc(s2/2,n/2).^(1/n))./sqrt(s2),1,n);
toc
subplot(1,2,1);plot3(X(:,1),X(:,2),X(:,3),'r.','markersize',1);
axis equal;rotate3d off; rotate3d on;drawnow;shg;
ax = axis;

tic
X = X.*repmat(r*(rand(m,1).^(1/n))./sqrt(s2),1,n);
toc
subplot(1,2,2);plot3(X(:,1),X(:,2),X(:,3),'r.','markersize',1);
axis equal;rotate3d off; rotate3d on;drawnow;shg;
axis(ax);

pause

m = 30000;n = 20; r = 2;
X = randn(m,n);
s2 = sum(X.^2,2);
tic
X = X.*repmat(r*(gammainc(s2/2,n/2).^(1/n))./sqrt(s2),1,n);
toc
subplot(1,2,1);plot3(X(:,1),X(:,2),X(:,3),'r.','markersize',1);
axis equal;rotate3d off; rotate3d on;drawnow;shg;
ax = axis;

tic
X = X.*repmat(r*(rand(m,1).^(1/n))./sqrt(s2),1,n);
toc
subplot(1,2,2);plot3(X(:,1),X(:,2),X(:,3),'r.','markersize',1);
axis equal;rotate3d off; rotate3d on;drawnow;shg;
axis(ax);

08 Jun 2012 Random Vectors with Fixed Sum Randomly and uniformly generates vectors with a specified sum and values in a specified interval. Author: Roger Stafford Olga Petrik

Contact us