Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 141
Kernel: SageMath 7.6

6.3 - The Euler Method ┬──┬ ノ( ゜-゜ノ)

Suppose x(t)x(t) is differentiable, then dxdt=limΔt0x(t+ΔT)x(t)Δt\frac{dx}{dt} = \lim_{\Delta t \to 0} \frac{x(t + \Delta T) - x(t)}{\Delta t}

So when Δt\Delta t is very small dxdtx(t+Δt)x(t)Δt\frac{dx}{dt} \approx \frac{x(t + \Delta t) - x(t)}{\Delta t} x(t+Δt)x(t)+Δtdxdtx(t+\Delta t) \approx x(t) + \Delta t \cdot \frac{dx}{dt}

We can use a discrete-time dynamical system to model a continous-time dinamical system dxdt=f(x,t)\frac{dx}{dt} = f(x,t) Δx=Δtf(x,t)\Delta x = \Delta t \cdot f(x,t)

OMG WHALES AGAIN (╯°□°)╯︵ ┻━┻

Variables B=B = Number of blue whales F=F = Number of fin whales

Assumptions ΔB=Δt(0.05B(1B150000)αBF)\Delta B = \Delta t (0.05B(1-\frac{B}{150000})-\alpha B F) ΔF=Δt(0.08F(1F400000)αBF)\Delta F = \Delta t (0.08F(1-\frac{F}{400000})-\alpha B F)

B0 = 5000 F0 = 70000 a = 10^(-7) dt = 0.25 f1(B,F) = 0.05*B*(1-B/150000) - a*B*F f2(B,F) = 0.08*F*(1-F/400000) - a*B*F L_B = [B0] L_F = [F0] for i in range(100): B_next = L_B[-1] + dt*f1(L_B[-1],L_F[-1]) F_next = L_F[-1] + dt*f2(L_B[-1],L_F[-1]) L_B.append(B_next) L_F.append(F_next) p1 = list_plot(L_B) p2 = list_plot(L_F, color="fuchsia") show(p1+p2)
Image in a Jupyter notebook

RLC Problem (o・・)ノ”(ᴗ ᴗ。)

Variables: vC=v_C = voltage across capacitor iC=i_C = current through capacitor vR=v_R = voltage across resistor iR=i_R = current through resistor vL=v_L = voltage across inductor iL=i_L = current through inductor

Assumptions: CdvCdt=iCC\frac{dv_C}{dt} = i_C vR=f(iR)v_R = f(i_R) LdiLdt=vLL\frac{di_L}{dt} = v_L iC=iR=iLi_C = i_R = i_L vC+vR+vL=0v_C + v_R + v_L = 0 L=1L = 1 C=1/5C = 1/5 f(x)=x3+4xf(x) = x^3 + 4x

Dynamical system: dvCdt=iLC\frac{dv_C}{dt} = \frac{i_L}{C} So ΔvC=Δt(iLC)\Delta v_C = \Delta t (\frac{i_L}{C}) diLdt=vC+f(iL)L\frac{di_L}{dt} = -\frac{v_C+f(iL)}{L} So ΔiL=Δt(vC+f(iL)L)\Delta i_L = \Delta t (-\frac{v_C+f(iL)}{L})

L = 1 C = 1 dt = 0.1 f(x) = x^3+4*x f1(vC,iL) = iL/C f2(vC,iL) = iL-iL^3-vC vC0 = 0.3 iL0 = 0.1 L_vC = [vC0] L_iL = [iL0] for i in range(400): vC_next = L_vC[-1] + dt*f1(L_vC[-1],L_iL[-1]) iL_next = L_iL[-1] + dt*f2(L_vC[-1],L_iL[-1]) L_vC.append(vC_next) L_iL.append(iL_next) p1 = list_plot(L_vC) p2 = list_plot(L_iL, color="fuchsia") show(p1+p2)
Image in a Jupyter notebook
list_plot(zip(L_vC,L_iL))
Image in a Jupyter notebook