Week 5 - Literature review: ODE Stability
explicit:
import numpy as np
import matplotlib.pyplot as plt
def explicit_euler(total_t,dt):
t = np.arange(0,t_total,dt)
y = np.zeros(len(t))
for i in range(1,len(t)):
y[i] = y[i-1]+dt*(-1000*y[i-1]-np.exp(-t[i-1]))
return [t,y]
def implicit_euler(total_t,dt):
t = np.arange(0,total_t,dt)
y = np.zeros(len(t))
for i in range(1,len(t)):
y[i] = (y[i-1]-np.exp(-t[i-1])*dt)/(1+1000*dt)
return [t,y]
def analytical_euler(t_total,dt):
t = np.arange(0,t_total,dt)
y = np.zeros(len(t))
for i in range(1,len(t)):
y[i] = (np.exp(-1000*t[i])*(1-np.exp((1000-1)*t[i])))/(1000-1)
return [t,y]
t_total = 0.1
c = 0.1
dt = 1.8e-6
t,y_explicit = explicit_euler(t_total,dt)
t,y_implicit = implicit_euler(t_total,dt)
t,y_analytical = analytical_euler(t_total,dt)
plt.plot(t,y_explicit,'.',color = 'green')
plt.plot(t,y_implicit,'.',color = 'red')
plt.plot(t,y_analytical,'.',color = 'orange')
plt.legend(['explicit','implicit','analytical'])
plt.xlabel('time')
plt.ylabel('y')
plt.show()
ode become stable:
when dt = total time/constant
so ode becomes unstable depending on its time step incremnt value according to that equation
2:
in engineering solutions ,to obtain a solution a stable method must be choosen ,if we didnt choose stable method we did nt get the solution what we expect ,so proper solution is to adopted for obtaining accurate solutions
3:
yes stability condition can be derived for all problems and its depend upon ode