-1

I would like to generate a Gaussian plot with n(say n=25) random numbers whose sum is 1000. I would like to use MATLAB or Excel(Preferably MATLAB) to generate this plot. I need to have a mathematical equation generated from the Plot with varying Standard Deviation values.

Thanks..

Shiva Teja
  • 27
  • 6

1 Answers1

0
X=40*randn(1, 25);
X (25)=1000-sum (X (1:24));
figure ();
hist (X);

Note: there are several possibilities to fulfill your requirements. If this is not the solution you intended, please provide more details.

Edit:

SumX = 1000;
N=25;
MinX=0;
MaxX=250;
StdX =20;
while true
    X=randn(1, N)*StdX;
    X=X-sum(X)/N+SumX/N;
    if all(X>=MinX) && all(X <=MaxX)
        break;
    end
end
NeitherNor
  • 254
  • 2
  • 7
  • The random numbers generated should form a Gaussian plot.. and the range of random numbers is 0 to 250.. I need to have an equation generated from the plot – Shiva Teja Dec 15 '15 at 06:13
  • 1
    I think you rather have a math than a matlab problem. If your 25 random numbers have to sum to 1000, this implies that they are bot independently distributed. I think you might be able to do some "cheating" such that the distribution looks like Gaussian, but the question for me is what the mathematical interpretation of such a plot is. Furthermore, if your distribution is Gaussian, this collides with your range request. You might manage to get 99.999% of the samples into the range, but never 100% – NeitherNor Dec 15 '15 at 06:25
  • The random numbers generated from the below link are in my desired range.. But I need a Gaussian plot out of it http://stackoverflow.com/questions/21782329/generate-n-random-numbers-whose-sum-is-constant-k-excel# – Shiva Teja Dec 15 '15 at 06:28
  • As I said, there is a logical problem in your request. To understand this, consider n=1. Then you have the question of: how to generate a random number X which is Gaussian distributed AND equal to 1000. If you are not allowing for a degenerated Gaussian distribution with variance 0, your requests do not fit together. Furthermore, a Gaussian distribution has an infinite tail. However, I will modify my answer such that the result will look like as if it would fulfill your request, but, mathematically, does not. – NeitherNor Dec 15 '15 at 07:03
  • Its a Biological interpretation.. Initially I have 1000 eggs are of same age... They'll hatch in to caterpillar in 27 to 33 days( 30 +-3) with interval of 0.25.. Hatching to a caterpillar will form a near Gaussian plot.. So i need to divide this 1000 to 25 values.. i would like to generate an equation for that... – Shiva Teja Dec 17 '15 at 09:35
  • I have the strong impression that you might have accidentally used well defined mathematical formulations having nothing to do with your actual problem. Correct me if I am wrong, but I summarize what I believe your actual question is: you have N=1000 measurements of hatching times, which are roughly gaussian distributed with mean 30 and standard deviation 3. The time resolution of your data is 0.25. You want the code of a matlab function generating a histogram for this data, showing for all of the 25 possible hatching times how many of the 1000 eggs hatched. – NeitherNor Dec 18 '15 at 08:34
  • If this is correct, the matlab functions you are searching is histogram. Open matlab and type in "doc histogram". If your matlab version is old, type in "doc hist". A window will open with in detail description and examples what you have to do to get your histogram plot. – NeitherNor Dec 18 '15 at 08:34