Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

B.

sc CSTT STh SemesBe


SPmulahon and Modei'ng
C3c317
a b Tagk oL Ankitary
TPtie Continuous Syden Stmuatr-Chemical Keackong
ab task a to 4mul ale
|Objecke: The objeckve *f ths reachon fn C
Chemfcal
Cond nuous &lem-

Reraed Thealy: ?n whfch he 4aJe


A
Contnuous Sy&tem
s one

oveB time. E head of waen


Consuo
chane
Vauable3 Change
beh'nd a dam
os
uhere two chemicals Chi ycka react h
kets Consfder a case
cJ.c2 C3 ane 7he amo onts of
thfrd chemfcal Chs Df
Pmduce a
Pncreae
ingtant ef tme t, the rates o4
'chs.Cho,cha at any
CI,C2, c3 are. k : Ci(2 -2k2G
dt
2 k 2(3- ki C C2
where k K2 ae Congtnk

as.ue chemfcals Chi vch2 a e mixed.fhe veachim


As soon
CJC2 and ca fn the mhore
on

tards vthe amounds e he simul ahon of redchon twf


me Pmgegres
Changfhg as ue 2 , reg drgfererd
delemre he
deto tate effe ytem ie. a cvery Smal ?ncreme d
PoPnHs n ho. SAanhn at zemime, the
ta len a each elep TutE) c2 (E)nd caCt) ave
|me s t At
a r e t, hen at tme
quanhte of the 3 Chemic s
qvanhtesare cult +At) Cult) +deiCEE Same l"s tr e.(G
ef chu, Ch xcks
Taking Ci(o), C2co) pe3(o) as the quanhhes he Hale t
te
ie. tohen the yezckon 4arts,
at tine Zeho,
&yadon at bme At w e

Cu (tE Cu Co) +l k Calo) -

Ki Ca( o)x o (o) 7st


C2At) c2C0)+ Lo Cal o)- K a u (0) ]A lo)* c2
CaAt) Ca ( + kAG (oo*C2 (o) - 2k2Cs ()]4E
Source Code
9nCIUde <std8.h>
include imath-h>
*Pncude Stdiibh>

n+mainC

Hoat C [i 0007, c200 oJ, lJ0 00]


Ca
dt= O«00L
Hoa KI 0.02, k2r 0 0 ki, ke are Conlfan
Ch, Cha,chg
Cy(2, C3 7Te amo unl of chemicais

CCo So.0, c2 loJ- 350, Calo] 0-0; J . re


acfon
sents The
re

t 4fme- 100 . 0: 114ime repre


lo at 00,

FTLE fP: w"); "

Pfopen ('"labos.bxt", Sznefoider Pn


are
Imako SUre a u fies
Cwhfelt2: bme)

Cu [?3 +[ k2
* C3 CP] -Ki * CI Lr3* C2 Cr])*dE
cuT+13 J*c2C73)*de
C2C3+( ke * (a CJ- k
* c C
C2Ct -
Ca C
2.0*(kJ* CJt/) C2 Cf]
-KeX

cgC+: C3[7]+

o " , cu Ci), calr), C»CiJ


printt (1P, "In Tot

tttdt

rese CfP)"Peackm &hmuialed "):


printt
Yehurn 0
Output: and gehorle e chut
n Sehlhe tet! daBa în
ezcer

So

2D

J0

ine chal fer Chemtal euc


F Seallen piot

Iontw Siomg simulakm


ine hog The
scater ptof
Hence, he The en hn
uous aem mu1a
Cohfch
Chermi Cal hoaohon
tes
5h Semes
.SC csTT

Simolakon
Modeling
Csc 3/ AndEPane
a b Tas 02

PHle Daeele Sydem Sinulaen simuae a dne


dask Po
eCkveThe objeckve of this Mode Calo
Smuza
Smulba
vsing
Sy&lem by ëekmahng P
elaked Thebdy Po hieh Hhe slale vahabe Chare
Disc nele uxlem is one fn fme. An example iaa ben
pofnds
0nty ata drscte sete a methoe o etmak the v a w e
Mante Callo Amulahon
P
Pi 's based m the fdes h
byushy Jandlom sampng.
P hat tevdad Poto too pais,
and you
tou hava haglm
pbabiLA,
tshD that e g n , h e
andomIy selecd pbrnis be
wiu au Pn one pad the othe Can
o
| that a
hat apofnt
elhmate fhe relakve e a s ef u R
tro pash.
Us ed o

Soura Cocke
#nude Lioktream
Lc9tdIPb>
t mtlvde
Pnciude Lchsme
nuuode 4graphieg-hs
hardum andy Coordinales betwan -12
Foncfon to penelake
vofd generale Yandon-point double wr, Jouble
vofd v)
(doubie) Yand(O/2AN NAY*2 -
(doobie) fand) RAND. NAX *2 -J;

nt maio ()
enasn
Pnt i, cirtle poïnts so, S9vamepo?nds:0,
dobe
s4d: Cout 4 "En ter the nunber a ferah'on
S+d: cin PHetadton
t windOw I/T%kalze Jhe grap hics winod
(6o0, 60);
ouw (600, 600) '
tho Vandom noynns
Srand sead for
Telo)): lsol the
Draw CPrtle y
Squane
Cicle 360, 300, 200 )
Fettangle (100, Joo, So0,So)
PertbYD Monfe caslo SPmulah 0

For li-o, 9 ?lerahan; la)


generale Vandorn. Point( g),
Tngde the cine
Check Pthe pont eg

cfclepomts ++
Putpizel( 30o + * 200, 30o +y #2 00, 7 R¬Eu):

else

putpell300+ *200 Beo +y *200


RED);
Sg vanepofnts +t,
3
II Esdimale He vawe of p*
double pi eskmale =
4«0 *
Cruepos Sqoarepe'pts
Cout 4e'" Estimaled valoe P " : 42 p? estmate
LLStd::endk
l h a l t o r the usen t preas a Ks before chos ing the widh
U
ol ch );
closeg7aph ();
Vetn 0;
Ovtpul: lo0ooo
Eoen the num bet of dnarion
3.1376
t&henaled vawe e pi:

aphios Wndo

ConctuSon
Armu lal ed he
dis erede s
ydem by ekmaky
Hona, we
Monte Carlo simuaton
he vawe e pr dSing
sc. cs1T Sh SemesleY
C3C 3/9 Stmuahon u Modelrng
Ankit Pangeni
Lab Ta 03 ono
e : Pandom Nom ber Smulaton)nenerakn
eckue The objethve ef his ask Ps t girtJennade
random numbes Using:
NiLed Conguentia Method
Addhve guetial Method
3
Mu4TpIPcakve Cong venHPal Hethod
4Ahmelie Congrvenka Hethod

Rela ted Theok


Kandom nUmbers are The samples r a u n m a unirnly
dPgtibu led randem valable bekwen Some Sassped fneuag
they have egual prbabi o o curtence
ethode ef jenenahon ef Randem ombs
'nean onyruenkal Methud
X4l Xf4 c)mod m, P-o.J. 2, - -

ohen,
Cwhe, Xo fs Calind seod, a is caad Con& ant muiphieu,
CPs Caued Pncrement and m fs caled modulug

Case 1: Uw ben c =o, Xi4l- aXF) modm Ps caltod mulh plicake C H.


Case2 Oon t0, X1r: a Xi+c) mod m P's Catad mited c.
CM
Cage 3: whn 3el, Xih =
(Xi tc) mod m is cakedadd?Ave
Asmek (ongrventat Hethad
Vr2-+ Yrau) mod m whw, Yi» Y:m
Seeds

Cegvent Vandom numbons Pi P mut hawe wo ---.

pmpoTtan &tats kal pmpetes


N enyd here
()norrm: They houol be eg vauly pDbable
Pndpendera: Tre randon numbes ennaled numbera.
nw
.

independent ean pa handern


SouTe Code:
Pnctude 4sldo.b
de 2conio-b
nt mainC) but br
random numbas
Yienet
'nt o,X »Xj /1o-sead, Ps nexrar
Xo,XY the nd geed RY2
Xi is
anfheh,
C-increment, m-medu
mukplieY,
aC m)]acConslant
nE Pr.num, mathod' ber
numbesgerrars
vandom
aray C207 : / o store the
Pine "hoose Ihe method:n");
Jfnear Congnuenkal
Mefhd "J
PintInJ. longrvendal Methd \o");
Printt"In 2 Aritbmehc
San 7od", umethod);
Swtchlmethod
Cale :
paPntk"|o Enler the seed value ko: ");
S Can"oTod" xo;
moduus m:")D;
Printh"» Enter he
Scan o70d", um),

printt HoLo many Yandom numbens ou ukant o qenank: "


SCantl"od"vn
otl"o whtch method you want to per/ovn ');
Orinttn J. Mited Conguehhau "):
printt h . Add?sve Conqrvenha ");
P'rinty "n 3. HuhdPcakvë lung rvenkzi In");
Soant"7od") unum);

Swch num)

COse
Case / Enter the congland
molteplier 7:
")
P Scant" ood, a)
prind "n
Enter the ircrement C:
7od") c); "
Scant "
(C=o) rtandam nonbe
o PP2n,?++) / Sop h generate
XI(7*Yoc) 70 m
3TYay [f] XJ,
Xo-
Pntt|n YTod *od ",i, aray li3)D
pintf"E");
3
else
prin+}"for nined cong uenka) vawe of c Cant be em'");

Cage 2
Pin o enter the ?nereme c');
Scan"olod", ) ;

X J *
+c) 1om Xo
aYray C]:X2'
Xo X
p n " | o lhe generaBed raneom numbes are:");
or ( fl -
n, ?++)
printtl In X rod- 7od",?, arvayC );
prin (" 1E "); brezc,

Cale 8:
Caße nttn Enr the Condant
Scant o1od", a);
mukp lir a:");

2
a* Xo) "7o m
aTTay i] X1,
X0
PiH nThe generaBed
random numbs are:"),
are:"),
or(P 94 -D; u+)
n n Xmod: od",?, 7YYay i J )
PraintH")E"),
( breaK)
3
break
Case 2
Prin In Enter the seedvawe Xo: ")
Scant" 01od", Xo),
Pitt("]n Entor the seed vawe Xi: ")
Scan 07od"', X);
rind n Enter the moduus m: ");
Scant("od")um);
" n How many mandm numbors yoo want
Jenarae: ");
Scan' od", un);

X2- (Xb+Xn) 7o m

X0X1
Y=X,
bin"o Xlods nod", ? +u,
7*ra4[)),
printt"E");
re k

Yetm D
AtMDAsnkAi

Outpot
Choose the methd:
"nay lng Tvenhal mathod
1Thmmea¢ longruenhal mathod
2
Enter tho seed y Zwe io:S
Enter he seed vawe Xi
Eoterthe modulus m:Jo
HLo
many ranolem numbos y ou
J
cwont to qenavak Jo
he generafed rand orm numbes ae
Xa
X3:7
Xy=9
X3

3:9
XD 0
Xn9
3 st( STT sth SemesBen.
Cse 3/0Stmulatn Hodeling Panger

ab Task 0Sand o6. -

ber ustn Ch.s9vane x pokar ks


He Tesd of Randam
num

fask Ps fesd
fhe
Objeckue: The objechkve
al this ker te
using
Ch7- squ7re 2 Po
andom numbers

Rolal edTraoy
ChtSqvane tet andm numbees
unrorm pavpeoty
epds he
Tuse the Samplo dzhshe:
(or-E
fn the
f-th c l s , t:
3s the obceve mymbes jhe naClais
he, l0 ith class, e n
fs
numbn în the
t h e epettes

tu
t a
baseo m
a based
n
Po en-et ndeperdenca
Tndependen
Tey i he ted for Jepeated
epeaed
whn« wh0«
he poker dgls tertain
z

he
Aaa
A rn
d

wth
wtch teMs
deds ffn
7reguency Thi's
This tek na
teW n a my
et h e d
dts
s
also
also
nwmben.
bu4
buj
Sehies ebd
Sevs
vence e numbe,
nombe he epeceel

enpeckeel
aw
va we
e

0mas o4
the seg The numbee
s
&e n
nuummbbee
s

each Bf n'n a a
Compriiny e ds s the
Ch?.
mbinatm mans e
e by dne
de AhHe
*
e
vaue

eaCh tbselved aceeptance s


is
wrtn the aceeptane po h ' b le
le
Cmpand
The
he
the
he Pobb brr
vawe o
for alt
tndependene. for a l vewe

Sqvase te for
or Che. S9vare S ou
S m
acceplabe Freuat
Ck.sgvare
vawe
vaR oo an fe npdene
enveod sa
pbs adeaHs
&pectked
e
Combinatns
drexchn
degret ef
en
ro 1270
0UTCO Cods
h c tude 4sldroh»
nctude zconfo»
Pnctude t stdiîb-h>
Poctude 24ime.h>
Jo //no o tndetvas
dene TNTEAVALs a9sumad ag- S 9o 2 d(:9
tFdefre +abylaBed. vawe J6.919//we
Pnt ma'n vod)
random no to be genvated
Int o- ,; //oz Se ed, Ziz nett
Cneremenb, memed
t
S C:3, m:Joo; / ar(ons/am mulhpior,
fnt nl0o; }) s/ze e he Samp le.
nt b[INTEAVALS): So, Jo»20, 30, 40,50o,6o, 70 90, go ; //ortuer bounds
nt ublTn fER VALS]-919,29.39,49,r9, 69,99,9 9,39};/|uppex bound f mieu
nt observed [TNTERVALS) So}. ezpeeled, N=0
toBa o ohseved kr y
bsekveregvencie, ezpecded treq ueg,
sdoe the Jandom numbers feneakd
Ynt .array [1 00); I]4»
loat calcwlabon l2o, final each TnBewal

*Catw 1akon s
fhe vatwe e lor-er) Jer ef Intevzs */
total cat w/aBed au
vawe

and hal fs he

Jandom numbexs |n *): 7re:


Prnt fThe Jandom nurmbery
betn o u9g vhing mir/ L
'en ; f4+) lgenerale
OTl0
Ai (a* o +C) Tom

printfl" od", 7TrayT?7);

obso ved regveny pr each n


o i z n i + ) carwaky

orf:0 j sj++)
TNTERVALS

[I>= Jbtj7 yg zmay ti]e= ubt7)


H(7rray
obs elved Cf]++ breat, 3 3
*

/catcw lahn ef n (tota frepventy), (atwlafn (o?-tr°/


na.
enpecled- n)TTERVAAS:
forll:oji INTERvALS; P4 4)
cawant)- (loal) ((obsexved CII- ezpeded)* lohsetvedt t
(elved ti]-Xjel
epetled,
Tnal: nal + (alwlahon [?3;
NN 0bselved Li);

|Wdisplay in tzbe -foat


");
priniH"n-- OP ElE Er )ElE U0r-Er)*{0n-E)) JEr")
prinl"n Swo |tlt ")
potnln--..----
f+4)
ort frof2Jo;
7od EIE 7od
ElE o", f+4, ohseudtt
printh"n mad )tlbczlwlakm CP] )>
enpected, . -");

printt"In. --
Ana);
)elE 7od lElEJEE To',N,
Tintt"ln P's atp
calcoiated vawe Contdude Ho
tabuialed y
|/lCompaue
vaiue)
1 l 2- tabulzdel vawe -
p. So, e
Printnn The
catcwlakd vawe
: Tofk.7aby/aded
/abu afed.vaue)
hejeeled."1fnal,
nUi hypothesis s not

nok.
nd > Taby/ted
vaue-

printt"lo The catw lakd


vawe.

So the nuif hypothesis


?s rejecked.", hnal, tabvatkd_vaue)
3
etuTn o
Output
h e andom numbes
93 68 93 Jg 93 68 us 1p 33
u3 18
69
39
39 93 6g 43 J 93
97 6
6 u3 19 93 68 3 18 93 68 3 J I3 6y y3 Jp
U3 19 g3
u3 Je 93 68
43 19 93 68 u3 1 9? 6p 43
43 9 68 u ? 93 69
93
43 18 UJ I8 93 68 3 Je
69 ug8 99 68
8Ja 93
93 68 u3 JP9Z
68 3 s 53 68 3993 69 3

Or E
(0i-Fi) *(0,-E:))/G
SWo 0
Jo J0 0000 0
19 6 00o00
Jo
2 2 J0 b00 000

3 0
L
22:Soo060
2s 0
J0 00O 000
0
22 So 0 00
2
10 00 o000
0
JO J0. 00 0 000
22.So00o0
Jo 2S
-
J4S 99999

Jo0

Tabu/ates vaLve - J6 3190a:|


v Zwer JuS. /9999 ?
Tho Catculaded
hypothes/s 1s rejecled
So, fhe n//
PokenTe
The pokan ted tor indsnardena is baseol m.tue Tegvency wh
in a soies o rumbng
which ceohin dfis are epeated
Chitqoane stakrh v aup* ejee fe hypttnes
useg the
n y digA Pom dex hme ane 5 possfk:

bab l 4 diferent d ) : Jx o0gxo px 0.9: ofby

2Prtbabi,[4 Some oart) XCl4)= 0.001


JXO1X0-1xpI

3 Probabit,{3 dz a kind): Jx01 xo-j X 0 3% (l9) =6.ert


4) Probabilityy bne paih) /xo1x O9x 0ly LCh2) = 0432
5) Probabity [ ho6 pafh): J- 0 Soy- 0.001- 0.076-0-e92 0.029

.
doUTe Code

Il4 dgiI Povn tes


i n c tude <ddro ks
CHTSQoARE G.49
TAD
H defrne
Pnt main ()

Jreu. a.kind, me par,tue


pu
our, ofa.ind,
fnt toor drH
QUARE - 00;
Da AL LHDS 0 001, 0. 036, 0 32, 0-02?
1oat pbabiJFkeaLs]:
{ 0So",
toat 'epecled veguencyl):
numbens drd you generaé, "):
printtl"How Many
fcan "rlod', vn), af)»") Scant/od
Obieruedegueneiy
pmintt(".tnte fhe
printtlIn four ferent
olig e : ");
Scanf "od", pur.di# J;
same cpt:"):
pridl"In tour
oor.ofakind);
SCant" 1od", 2
printh Thro oa kind: ");
SCanb"»d"y thre, a Kind);
pindl")n One Paiv") ;
SCantl'ed'", Lni.pair)
printt")»Tuws pa': ");
cant s1od", hwrpal),
Hwordrff 4spur.oa.kind fhrn ond4 mepa'reaepa
) printtl")The Sum s ns eguai b 7od", »)

ee

in obsonved.freqvenuy [r1:{YordeH, foor rind7


a . kiho, me. pal r, fiso pai
pindt"] The "abseves regvenci aen"):
forliro, iis; fa4) { prid|l od" bsenveo treguenga); }
brinttl/n And her vsperkve expecked qtregvenua aveln

erpecledfvaqoanuy(g)= pobabiLRes Ci ]*n; }

prindfl") t Tud", (int) expechd-fegveny l« 3J;3

CAL H2sduAREt=(l
(obsorved. freqvenyl1 -evpetkdtregvenyEA7)*
(oherved eg veneyts 7. epethetregvenatJg))
expected.treq veny t);
3
painthl "lohe SumCauwladed chr sguare sdabehes s
Tok", c ALL (HEs AuA RE J;
errintt"The tabutated vae fr Chirgvave ii Tof , TAR

CHtsgop6),
AL CHTs8vARE TARHTS&UA

inif["n So,fhe genorakd ronda ne


indaperdes.

['"lo So,fhe gentaled handdon numbor


pindk
na ndep endend.");

u-po ak: Joo 0D


numbrsdid yo gennak:
Joe00
How many
Ender e rbiowed fregenuies f:
Four oeforau dyih: SIS
fourr Same digik: 13
kind: 362
Jhre a
one pa: 4225
Tuwo pair: 26
fregvenies ae
The bsewed 2o
362 4225
Siso 13
expech regveneieg ase
And fheir respehe
Soyo Jo 39 4320 2
lahrhas6.88 202
Cnlwtakd chigvame
The Sum o vane ie 3 ugoo
heabusaded
vawe
r Cns indpendund
are
numbeng
andero
genna
S he

You might also like