



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
These lecture slides are delivered at The LNM Institute of Information Technology by Dr. Sham Thakur for subject of Mathematical Modeling and Simulation. Its main points are: Models, Random, Processes, Classification, Pseudorandom, Numbers, Linear, Congruential, Generators, Sequence
Typology: Slides
1 / 27
This page cannot be seen from the preview
Don't miss anything!
Random numbers for use in computer programs
can be classified into different categories:
Truly random numbers: Obviously these cannot be
produced by computer programs, They must be
supplied by an external source.
Such sequences are available (e.g. in tabular
forms), but clumsy to use and often not sufficient
in terms of speed and number.
Random Numbers
numbers are deterministic.
true random sequences.
in computations.
generated by a deterministic process.
sequences.
Random Numbers
Example 1: Model a system Using Random Numbers
Consider a basket having 5 red balls and total 20 balls.
Pick a ball without looking and will it be a red?
Call this as an event A. The event A has probability p and the
probability of not happening of A is 1 – p. Clearly the outcome B has
the probability 1 – p.
The computer will simulate this experiment by generating a random
occurred if the value of is 0 p
and the event B will occur if p ^1
p 1 - p
p 1
Example 1: Model a system Using Random Numbers
The computer will
simulate this
experiment by
generating a random
interval [0, 1] and
we will call the event
A has occurred if the
than p.
Here p = 5/20=0.
Random Number
Event A Event B
Program in MATLAB
N_parent = 1000; N_daughter = 0; tmax = 200; probability_of_decay = 0.01; rand('state', 0) % initialize the generator to state zero t = 0; for i = 1: tmax xt(i) = t; xx(i) = N_parent; yy(i) = N_daughter; M = N_parent; for k = 1: M x = rand; if x < probability_of_decay N_parent = N_parent - 1; N_daughter = N_daughter + 1; end end t = t + 1 end plot(xt, xx, 'LineWidth',2) hold on plot(xt, yy, 'LineWidth',2) axis([0 tmax 0 1200]) xlabel('time, t') ylabel('Number ') Grid hold off
t N( t) N(o) e
where, is a constant related to the probability of decay per second for the parent nucleus.
Program in MATLAB
Here is program to generate random numbers and then plot them in 2D figure.
rand('state', 0) % initial state nframes = 100 ; % number of frames for movie for j = 1: nframes j axis([-1.2 1.2 -1.2 1.2]) hold on for k = 1: N x = 1.0 - 2.rand; y = 1.0 - 2.rand;
plot(x, y, 'b:.') hold on
end m(k)= getframe; end
Here random numbers are generted and plotted and you can see they are everywhere in this figure. That is no preferred place.
We must keep in view that the random number generator will provide the same
sequence of numbers again if it was initiated by the same number called ‘state’
or ‘seed’. If the seed is random or generated from a calendar/clock circuit of
the computer then the sequence will be different.
Random Distributions
MATLAB provides randn
function for Gaussian
distribution based random
numbers and arrays. Its general
synopsis is Y = randn(m,n)
and it will return m × n matix of
random entries with average
zero and variance equal to one.
The randn by itself returns a scalar value when called. Its state can be set by
randn(‘state’,j) command.
-3 -2 -1 0 1 2 3
0.
0.
0.
0.
0.
0.
0.
Deviation
h(z)^ Mean Value
The value of z
Random Distributions
Figure: The Gaussian distribution obtained from MATLAB
Normal Random Distributions
Normal Random Distributions
% Program to generate 20 bins of a normal distributed
Max_bins = 20;
randn('state', 0) % initialize the generator to state zero
y = randn(90000,1);
n = hist(y, Max_bins) % converts the data from y into 20 bins
bar(n) % plots the data as a bar graph