Showing posts with label Simulation and Modeling. Show all posts
Showing posts with label Simulation and Modeling. Show all posts

Wednesday, June 19, 2013

Random Numbers Generation & Chi-Squared Test for their Uniformity in C++

Continuous uniformly distributed random numbers means the set of random numbers where probability of any number in any integral within a certain range of values is proportional to the ratio of the interval size to the range. The generated random numbers require to be independent & uniform in distribution. There are many different methods to generate the random numbers. 
They are: 
  • Random numbers from table. 
  • From hardwired device. 
  • Using pseudo Number generation. 

In linear congruential method, we use one initial number (rcalled seed) and few constants. Using the seed and the formula, 
                       ri+1 = (ri ×a + b) (modulo m) 

Thursday, May 23, 2013

Modeling & Simulation of Chemical Reaction | Continuous System Simulation | C++ Implementation

Chemical reactions exhibit dynamic equilibrium, which means that a combination reaction is also accomplished by the reverse process of decomposition reaction. At the steady state the rates of the forward and the backward reaction is same.

In addition to the forward reaction where Ch1 and Ch2 react to produce Ch3, there may also be backward reaction, where by, Ch3 decomposes back into Ch1 and Ch2. Let the rate of formation of Ch3 be proportional to the product of the amounts Ch1 and Ch2 present in the mixture and let the rate of decomposition of Ch3 be proportional to its amount in the mixture. 
Let us consider C1, C2  and C3 Amount of Ch1, Ch2 and Ch3 at any instant of time t, the rate of increase of C1, C2& C3 are given by the following differential equations:

dC1/dt = K1C3– K1C1C2
dC2/dt = K2C3– K1C1C2
dC3/dt=2K1C1C2-2K2C3

Where K1and K2 are constants.