how to modifly the random number generator

  • Follow


I have created a simple system which generates 2 random numbers that always add to 1.  I did this by using 2 uniform random number generators and an adder which sums the results together.  I took the sum and ran it into 2 dividers so that each divider was dividing the original random number by the sum of the 2 random numbers to get 2 random numbers that add to one.  I hooked a scope up to the dividers and realized I was not getting a single random number.  This random number generator is a subsystem of a bigger system which can only use 1 value.  I'm wondering if the random number generator is the wrong block.  It seems the only thing I can change is the range of numbers, seed and sample time.

Can anyone help me with this?
0
Reply Susan 3/10/2010 7:34:09 PM

Susan wrote:
> I have created a simple system which generates 2 random numbers that 
> always add to 1.  I did this by using 2 uniform random number generators 
> and an adder which sums the results together.  I took the sum and ran it 
> into 2 dividers so that each divider was dividing the original random 
> number by the sum of the 2 random numbers to get 2 random numbers that 
> add to one.  I hooked a scope up to the dividers and realized I was not 
> getting a single random number.  This random number generator is a 
> subsystem of a bigger system which can only use 1 value.  I'm wondering 
> if the random number generator is the wrong block.  It seems the only 
> thing I can change is the range of numbers, seed and sample time.
> 
> Can anyone help me with this?

Why not simply take the first rnv and generate the second by subtracting 
the first from one?


I don't follow the problem as stated in "and realized I was not getting 
a single random number".  What, specifically, does that mean?

Think need more detail if above suggestion doesn't suit.

Actually, I think I realize I don't understand what the actual desired 
result is when combine first sentence and the statement about the larger 
system of which this is a subsystem....

--
0
Reply dpb 3/10/2010 7:45:46 PM


> > 
> > Can anyone help me with this?
> 
> Why not simply take the first rnv and generate the second by subtracting 
> the first from one?
> 
> 
> I don't follow the problem as stated in "and realized I was not getting 
> a single random number".  What, specifically, does that mean?
> 
> Think need more detail if above suggestion doesn't suit.
> 
> Actually, I think I realize I don't understand what the actual desired 
> result is when combine first sentence and the statement about the larger 
> system of which this is a subsystem....
> 
> --


> a single random number".  What, specifically, does that mean?
> 
> Think need more detail if above suggestion doesn't suit.
> 
> Actually, I think I realize I don't understand what the actual desired 
> result is when combine first sentence and the statement about the larger 
> system of which this is a subsystem....

I actually have 4 random number generators so simple subtraction will not work.  I was trying a simpler version first to get it to work.  I connected a display to the output of each divider and the final number generated for each divider adds to one. 

I want the random number to be constant over the sampling time.  The random number generator changes values over the sampling time.

Ignore the part about the subsystem, it is not important.
0
Reply Susan 3/10/2010 8:40:20 PM

"Susan " <susanreneemueller@gmail.com> wrote in message <hn903k$8l6$1@fred.mathworks.com>...

> I actually have 4 random number generators so simple subtraction will not work.  I was trying a simpler version first to get it to work.  I connected a display to the output of each divider and the final number generated for each divider adds to one. 
> 
> I want the random number to be constant over the sampling time.  The random number generator changes values over the sampling time.
> 

So why not tell us from the start what your problem is?

Scaling the total by dividing by the sum is not a good
way to generate uniform random numbers subject to a
constraint. In fact, they won't have a true uniform
distribution.

You can download randfixedsum from the file exchange
to give you the result you desire.

http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum

John
0
Reply John 3/10/2010 10:22:05 PM

What I'm doing is kind of hard to explain, but I'll try.  I have 4 air chambers, 4 solenoid valves, and 4 sensors.  I'm modeling each chamber, valve, and sensor as an independent system so a total of 4 subsystems.   Each subsystem has a chamber, pressure sensor, and a solenoid valve.   Each of the 4 subsystems is modeled as a transfer function.  The 4 transfer functions are run in parallel b/c they can be inflated and deflated without affecting each other.  

The 4 subsystems each share the air from 1 pump.  These chambers are independent of each other and at any given time have varying ratios of there actually pressure to their desired pressure set in the software that determines when to open and close a solenoid valve.  Let's assume for now that the desired pressure for each chamber is the same: 1 psi.  The air from the pump runs to a manifold where all the solenoids are located.  So if all the chambers are less than their desired pressure at any given point in time, all the solenoids will be open.  However in my model it is not accurate to assume each chamber is getting 1/4 of the air from the pump b/c the air will travel the path of least resistance.  Here's where the random number come into play.  I want to model a random percentage of 1 based on the "worst" case situation that all solenoids are open at the same time.

I know there are some inaccuracies with this model: as the pressure fills in one chamber the percentage of the total amount of air will not be constant.  I'm ignoring this issue and others for now.  I don't want as much critique on the process as I on how to generate a single random value which will be constant for the entire simulation time.  So instead of a ramp input or step input which would evenly divide the air 4 ways, I'm trying to generate a random number 0 and 1(I don't care if it's uniform) my adder and divider accurately create 4 random numbers that add to 1.

So all this to ask just one simple question.  Let's assume I just want to run a random number into a scope that will be the same random number for 10 seconds.  Can I do this?  I know how to do the rest.  Thanks for the help.
0
Reply Susan 3/11/2010 12:19:04 AM

Sorry for that long explanation.  I don't think it really helps answer the question, but I'd still like a reply.  

How can I get the random number block in Simulink to produce a single random number throughout the entire simulation time rather than changing over the simulation time?

I'd like to start by getting this to work with just the random number block and the scope.
0
Reply susanreneemueller 3/16/2010 3:42:22 AM

> How can I get the random number block in Simulink to produce a single random number throughout the entire simulation time rather than changing over the simulation time?

The above sentence seems to indicate that as far as the simulation is concerned you want a constant value.
It just happens that you want to generate that constant randomly at the start of the simulation.

If that's correct then don't use the random number generator block.
Use a constant block where the value of the constant is "rand(1)".
On intitialization the model will go to MATLAB and ask for a random number.
That number will then be used throughout the length of the simulation.

Phil.
0
Reply philNOSPAM (157) 3/16/2010 4:09:20 AM

6 Replies
233 Views

(page loaded in 0.321 seconds)

Similiar Articles:













7/28/2012 6:02:05 PM


Reply: