MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

In Matlab the code

v = rand(1,3); v = v/sum(v);

is sometimes suggested as a convenient means of generating three random variables, whose ranges are restricted to [0,1], which have a fixed sum of one. However, this procedure has the property that the area-wise density distribution of the three values, considered as cartesian coordinates in 3D space, is widely variable throughout the planar region of possible locations of v. For any given density value in the range of this density distribution, let A be the corresponding area of the subregion of all points whose density is less than or equal to this given value, and let P be the corresponding probability that v would lie in this subregion. The task is to write a function 'fixedsumarea' which receives P as an input and gives A as an output:

A = fixedsumarea(P);

You should assume that initially 'rand(1,3)' perfectly generates three independent random variables each uniformly distributed on [0,1], but subsequently each is modified by being divided by their mutual sum.

3 correct solutions
10 incorrect solutions

Last solution submitted on Oct 30, 2013

3 players like this problem

1 Comment

Roger Stafford
on 24 Feb 2012

I am pleased that you solved this problem, David. Congratulations! I didn't find any particularly easier way of solving it. The crucial step is showing that the probability density is proportional to your 1/y^3 for points within the corresponding "kite-shaped region". I used the Jacobian between two coordinate systems to show that. After dividing that region into two halves everything falls into place, though in my dotage I had to make heavy use of the Symbolic Toolbox to check for errors. (I hope this problem will serve as a warning to people who recommend this method of producing random numbers with a predetermined sum.) R. Stafford

1 Comment

Roger Stafford
on 23 Feb 2012

It is inherent in the definition of P here that the density, dP/dA, must increase as P increases and therefore dA/dP must decrease. In your proposed solution you have dA/dP increasing as P increases. R. Stafford

3 Comments