Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Generating Random numbers
Date: Thu, 2 Jul 2009 12:41:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 87
Message-ID: <h2i9st$hs5$1@fred.mathworks.com>
References: <d639c2c7-c672-4177-b89b-5c584755dabc@x5g2000yqk.googlegroups.com> <1602c78c-e855-4e3b-a483-4fa3ecba6ddb@h8g2000yqm.googlegroups.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246538461 18309 172.30.248.35 (2 Jul 2009 12:41:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 2 Jul 2009 12:41:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:552354


One thing you could do is the following:

A = (ceil(499.5+100*rand(10000,7)));
indicesOf4000 = find(sum(A,2)==4000);

Then, you could see the set of numbers by:

for k = 1:length(indicesOf4000)
    disp(num2str(A(indicesOf4000,:)))
end

If indicesOf4000 seems to be blank, you could either run A = ... again, or you could increase the number of sample sets from 10000 to a higher value.

Best.


Deivy <deivy71@gmail.com> wrote in message <1602c78c-e855-4e3b-a483-4fa3ecba6ddb@h8g2000yqm.googlegroups.com>...
> 
> Hi Sadik,
> Thanks for the reply.
> The choice of 3000 was accidental and it made the case bit easier.
> 
> What if the total is 4000, where it is not directly related to any of
> the numbers 500 and 600, and how do I do that.
> 
> Thank you,
> Regards,
> Deivy
> 
> 
> On Jul 2, 2:06?pm, "Sadik " <sadik.h...@gmail.com> wrote:
> > Hi Deivy,
> >
> > You actually have two sets only.
> >
> > A = {500,500,500,500,500,500}
> >
> > and
> >
> > B = {600,600,600,600,600}
> >
> > The best way to see it is this.
> >
> > Average is the sum divided by the number of elements, right?
> >
> > Therefore, in any case, you can have at most 6 elements and at least 5 elements. This means that you have to have corresponding averages of 500 and 600.
> >
> > Looking at set A, the only way that you can achieve the average value of 500 is that all are equal to 500. Otherwise, you will have elements going below 500, which is not acceptable.
> >
> > A similar argument is valid for set B.
> >
> > Hope this helps.
> >
> >
> >
> > Deivy <deiv...@gmail.com> wrote in message <4d2b33d7-9115-449a-bd83-5ec410153...@h8g2000yqm.googlegroups.com>...
> > > Hi Arun,
> > > Thanks for the reply.
> >
> > > Thanks Deivy
> >
> > > On Jul 2, 1:53?pm, arun <aragorn1...@gmail.com> wrote:
> > > > On Jul 2, 1:24?pm, Deivy <deiv...@gmail.com> wrote:
> >
> > > > > Hi Group,
> > > > > I would like to generate a set of numbers between 500 and 600 so that
> > > > > the total of them would be 3000.
> > > > > How many numbers to generate is unknown but the generated numbers
> > > > > should be within the range of 500 to 600 they should total to 3000.
> > > > > How do I do this in matlab.
> > > > > Could someone help me with this.
> >
> > > > > A small script that accomplishes this task is highly appreciated.
> >
> > > > > Thank you,
> > > > > Regards,
> > > > > Deivy
> >
> > > > 3000 = 500 * 6 = 600 * 5.
> >
> > > > so, the numbers you generate should be able to accomplish the task of
> > > > getting a sum of 3000 in 5 or 6 random numbers, otherwise the sum
> > > > would exceed 3000. so, its either 5 or 6. and they are not random, I
> > > > suppose.. unless the sum is >= 3000 but not == 3000.
> >
> > > > best,
> > > > arun.