Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Project: LS30A-1 F19
Views: 303
Kernel: SageMath (stable)

Week 04 - Euler’s Method

LS30A LAB 1B/1D

TA: Hao Lee

LA: Evelyn Malamut

Extra Exercise 1.4.9

The pier in Santa Monica, CA, is a popular destination for both tourists and locals. Visitors ride the Ferris wheel (F), eat ice cream (C), or just walk around on the pier(W). Write a dynamical model for the numbers of people engaged in these activities given the following assumptions. (Hint: Start by drawing a diagram of this system and labeling the stocks and flows.)

  • People entering the pier always start by just walking around.

  • E people enter the pier each minute.

  • Visitors leave at a constant per capita rate d. They can leave only when they are walking around.

  • Due to fear of nausea, people do not go directly from eating ice cream to riding the Ferris wheel.

  • Visitors prefer to go on the Ferris wheel with friends. Thus, the probability that any one individual will go on the Ferris wheel is proportional to the number of people walking around, with proportionality constant b.

  • Riders leave the Ferris wheel at per capita rate n.

  • When visitors leave the Ferris wheel, a fraction z of them go directly to eating ice cream. The others walk around.

  • Visitors who are walking around prefer to avoid long lines for ice cream. Thus, the per capita rate at which they get ice cream is proportional to the inverse of the number of people already doing so, with proportionality constant m.

  • People who are eating ice cream stop doing so at a constant per capita rate k.

How To Solve?

  • Define All State Variables!

  • Pay Attention to "per capita rate", "proportional", or "proportionality constant"

  • If state variable A -> B, make sure you "subtract A' and "add to B'"

States Variables: F, C, W

  • People entering the pier always start by just walking around.

  • E people enter the pier each minute.

w=Ew'=E
  • Visitors leave at a constant per capita rate d. They can leave only when they are walking around.

W=EdWW'=E-dW
  • Visitors prefer to go on the Ferris wheel with friends. Thus, the probability that any one individual will go on the Ferris wheel is proportional to the number of people walking around, with proportionality constant b.

F=bW2F' = bW^2W=bW2W' = -bW^2
  • Riders leave the Ferris wheel at per capita rate n.

  • When visitors leave the Ferris wheel, a fraction z of them go directly to eating ice cream. The others walk around.

F=nFF'=-nFC=znFC'=znFW=(1z)nFW'=(1-z)nF
  • Visitors who are walking around prefer to avoid long lines for ice cream. Thus, the per capita rate at which they get ice cream is proportional to the inverse of the number of people already doing so, with proportionality constant m.

W=mW1CW' = -mW\frac{1}{C}C=mW1CC' = mW\frac{1}{C}
  • Due to fear of nausea, people do not go directly from eating ice cream to riding the Ferris wheel.

  • People who are eating ice cream stop doing so at a constant per capita rate k.

C=kCC' = -kCW=kCW' = kC
F=bW2nFF' = bW^2-nFC=znF+mWCkCC' = znF+\frac{mW}{C}-kCW=EdWbW2+(1z)nFmWC+kCW' = E-dW-bW^2+(1-z)nF-\frac{mW}{C}+kC

Euler's Method

What it is?

model we have:

A=f(A)A'=f(A)

It is actually:

at=a(t+t)a(t)t=f(a)\frac{\triangle a}{\triangle t} = \frac{a(t+\triangle t)-a(t)}{\triangle t}=f(a)

For t\triangle t is very, very small!!

(X=tangent of xX' = \text{tangent of x})

f(x) = X' x_0 = 'start point/ initial point or value'

We have to simulate how x changes!!!

delta_x_0 = f(x_0)*step_size x_1 = x_0+delta_x_0

Only one time?

for i in srange('How many time I want to do it'): x_new = x_old+delta_x_old

How to storage it? Append it to a list!

xData.append(x_new)

Example: Use Euler method to simulate Exercise 1.4.15

X=VX'=V

V=km1XkfmVV'=-\underbrace{\frac{k}{m}}_1X-\frac{k_f}{m}V

X starts at 10,V starts at 0,k=5,m=5,kfk_f=1

Simulate for 100 sec.

xData=[10] vData=[0] total_time=100 step_size=0.01 tData = srange(0,total_time+step_size,step_size) k = 5 m=5 k_f=1 v_prime(x,v)=-k/m*x-k_f/m*v for i in srange(0,total_time,step_size): delta_x = vData[-1]*step_size delta_v = v_prime(xData[-1],vData[-1])*step_size xData.append(xData[-1]+delta_x) vData.append(vData[-1]+delta_v)
xPlot = list_plot(zip(tData,xData),axes_labels=['time (sec)','position(m)']) show(xPlot)
Image in a Jupyter notebook
vPlot = list_plot(zip(tData,vData),axes_labels=['time (sec)','velocity(m/s)']) show(vPlot)
Image in a Jupyter notebook

Choosing Step Size is Very Important!!!!

see if you set kfk_f = 0.01!!