Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 – Simulation of continuous systems

Similar presentations


Presentation on theme: "Chapter 2 – Simulation of continuous systems"— Presentation transcript:

1 Chapter 2 – Simulation of continuous systems
Examples Pure pursuit Chemical reactor Inventory Water reservoir General continuous simulation principle Distributed lag models

2 Pure pursuit Statement: Fighter aircraft sights an enemy bomber and starts chasing the bomber. Chase terminates when the fighter is close enough to the bomber and destroys the bomber or fighter gives up the chase after sometime Assumptions: Bomber (target) flies along a curve known to the fighter. The motion of fighter and bomber are two dimensional. Starting position of the bomber is known to the pursuer.

3 Model Bomber’s path is known means Bomber is at Time t 0 1 2 3 4 5 …
Xb(t) … Yb(t) … Fighter flies at constant speed Vf At the end of time t (may be 1 min) fighter changes his direction to point bomber Fighter is at (0,50) when he spots bomber

4 Model Figure showing F and B at time 0 and the direction of motion of F F 50 (0,0) B 80

5 Model Figure showing F and B at time 1 and time 2 and the direction of motion of F F (0,0) B (90,-2)

6 Model Figure showing F and B at time 2 and the direction of motion of F F (0,0) B (99,-6)

7 Fighter’s position At time 0 fighter is at (0,50) Xf(0)=0, Yf(0)=50
At time 0 bomber is at (80,0) Distance between F and B is sqrt( (80-0)2+(0- 50)2)) = d cos  =80/d sin  = -50/d d Xf(1)=Xf(0)+Vf* cos   Yf (1)=Yf(0)+ Vf* sin  80 Vf

8 General formula Xf(t+1)=Xf(t)+Vf*cos  Yf(t+1) = Yf(t)+Vf*sin 
sin  = [Yb(t)-Yf(t)]/Dist(t) cos  = [Xb(t)-Xf(t)]/Dist(t)

9 Algorithm Read endt, thresh, vf Read xb(t), yb(t) for t=1 to endt
Read xf(0), yf(0) For t=1 to endt dist=sqrt((xb(t)-xf(t))2+(yb(t)-yf(t)2)) If dist < thresh then exit Else sin  = [yb(t)-yf(t)]/dist cos  = [xb(t)-xf(t)]/dist t=t+1 xf(t+1)=xf(t)+vf*cos  yf(t+1) = yf(t)+vf*sin  End for If t > endt then Print “target escaped”, t Stop Else Print “target caught” End

10 Nature of pure pursuit problem
Continuous Deterministic

11 Chemical reaction Statement: In a certain chemical reaction when two substances A and B are brought together. They produce a substance C. It is known that 1 gm of A and 1 gm of B produce 2 gms of C. Rate of formation of C is proportional to amounts of A and B present. In addition to this forward reaction there is also a backward reaction decomposing C back to A and B. The rate of decomposition is proportional to amount of C present in the mixture. In other words at any time if a, b, c are the amounts of A, B, C the following differential equations express the rates of increases: da/dt= k2c – k1ab db/dt= k2c – k1ab dc/dt= 2k1k2ab – 2k2c where k1, k2 are rate constants The constants k1, k2 vary with temperature and pressure. Given k1, k2 and initial quantities of A and B we wish to determine how much of C has been produced at any time. Such determinations of rates of chemical reactions are important in many industrial applications.

12 Solution Start at time 0 and increment time by small step t. Assume quantities of chemicals are not altered from t to t+ t. a, b, c are found using equations a(t+ t) = a(t)+da(t)/dt * t … etc Suppose simulation is performed for time T, this T is divided into large number of t. Thus T= N * t. At time 0 we know a, b, c. That is a(0), b(0) and c(0) are known. Hence we can find a(t) =a(0)+[k2*c(0)-k1*a(0)*b(0)] and similar expressions for finding b, c.

13 Complete solution T, t, N Print a, b, c Stop
Read k1, k2, a(0), b(0), c(0) T, t, N Print a, b, c i=0 i=i+1 Stop y Compute a(i* t), b(i* t), c(i* t) I ≤ N n

14 Inventory Statement: Various costs in this problem are holding, ordering, loss of good will cost. The goal is to find reorder point and quantity to minimize the total cost. Assumptions: Lag time in receiving order = 3 days. Holding cost = 1 Re per item per night. Loss of good will cost = profit per item sale + 2 Rs = 10 Rs. Ordering cost = 75 Rs per order. Demand once lost is lost forever. Only one outstanding order allowed. Initial conditions: Starting inventory = 165. No outstanding orders. Demand: Any where between 0 to 99 and equi-probable.

15 Hand simulation Policy 1: Reorder point Reorder quantity - 150 Day Opening Demand Ending Order Costs Stock Stock Hold Order Loss yes no no no yes no no no ….. Find total cost for this policy 1.

16 Hand simulation Policy 2: Reorder point Reorder quantity - 150 Day Opening Demand Ending Order Costs Stock Stock Hold Order Loss yes no no no no yes ….. Find total cost for this policy And for more policies and find the policy with minimum total cost.

17 Solution A D stock=stock-dem Read P,Q n due=0? y
Initialize dueday, today, totcost, stock, due stock < P? B y totcost=totcost+75 dueday=today+3 due=1 stock=stock+Q due=0 C n today=dueday? y today=today+1 n D Generate dem Print totcost today <30? n dem <stock? n totcost=totcost+10*dem y y A C B

18 Water reservoir Mixed simulation (discrete as well as continuous). Rains at discrete days. Consumption is continuous. Statement: Water from a reservoir is supplied to people of a town. Rains are not routine. The volume of rain is random. The consumption is fixed. Excess water while it is raining goes waste. Output: Average wasted water, Average shortage You can generate in advance the rainy days, amount of rain. Assumptions: Capacity = gallons. Consumption = gallons per day.

19 Hand simulation Simulation for 10 days. Rainy days are 2, 9
Amount of rain are 5500, 2400 gallons Day Water Rain Consumption Wastage Shortage Average wastage = 500/10 Average shortage = 7600/10

20 Solution Read cap, inilev, nodays Initialize cons, wast,curlev, day=1
B n wast=wast+curlev+rain-cap Read cap, inilev, nodays day <=nodays? y Initialize cons, wast,curlev, day=1 avwast=wast/nodays avshort=short/nodays curlev=min(cap, curlev+rain) curlev=curlev-cons day=day+1 Generate rday, rain Print avwast, avshort n B n curlev < 0? day = rday? y y n curlev=0 short=short+cons-curlev curlev+rain >cap? y A

21 Continuous simulation principle
Find changes in the system state after an interval t Assume all changes to be at t+ t Update changes to state Test if end of simulation happens Continuous simulation also called fixed time step or time to time simulation

22 Distributed lag model / Recurrence model
In some model some variables are functions of others in the previous time step Common in econometrics Example I=2+0.1Y-1 T=0.2Y-1 Y=C-1+I-1+G-1 C=20+0.7(Y-1-T-1) Suffix -1 is used to denote lagged variable Given an initial set of values the values at the end of year are found I-Investment, Y-National income, G-Govt. expenditure, T-Taxes, C-Consumption

23 Lag models Example Given initial Y we can find remaining variables
I = 2+0.1Y-1 Y= (I+G) T=0.2Y C=20+0.7(Y-T) Given initial Y we can find remaining variables

24 Cobweb model P0=1.0, a=1.0, b=0.9, c=12.4, d=1.2
Example – linear supply and demand S=a+bP-1, D=c-dP where b, d > 0 For simplicity assume market is cleared each month That is D=S Given initial P, find S and using D=S find next P P0=1.0, a=1.0, b=0.9, c=12.4, d=1.2 S= P-1, D= P

25 Cobweb model Taking P0=1.0, we get S1=1.9
From D1=S1=1.9 we get P1=8.75 Using this P1 we get S2=8.875 and From D2=S2=8.875 we get P2=2.9375 Subsequent S and P are 3.644, 7.297; 7.567, ; 4.625, 6.479; 6.832, 4.64 …

26 Cobweb model - convergent
Time versus Price graph Price Time

27 Cobweb model - convergent
Supply and Demand graph Supply Quantity S / D Demand Price

28 Cobweb model S= -2.4+1.2P-1, D=10-0.9P Taking P0=5.0, we get S1= 3.6
From D1=S1=3.6 we get P1=7.1 Using this P1 we get S2=6.12 and From D2=S2=6.12 we get P2=4.3 Subsequent S and P are 2.76, 8.04; 9.648, 0.39; ... Price variations are 2.1, 2.8, 3.74, 7.65, … Variations are divergent

29 Cobweb model - divergent
Time versus Price graph Price Time

30 Cobweb model - divergent
Supply and Demand graph Supply Quantity S / D Demand Price

31 References Examples Pure pursuit – N.Deo, Chapter 1
Chemical reactor – N.Deo, Chapter 2 Inventory – N.Deo, Chapter 1 Water reservoir – N.Deo, Chapter 2 General continuous simulation principle – N.Deo, Chapter 3, 3.1 Distributed lag models - G.Gordon, Chapter 3


Download ppt "Chapter 2 – Simulation of continuous systems"

Similar presentations


Ads by Google