download
raw
734 Bytes
"""
Empirical estimation of the truncation error in a scheme.
Examples on the Forward Euler scheme for the decay ODE u'=-au.
"""
import numpy as np
import trunc_empir
def decay_FE(dt, N):
dt = float(dt)
t = np.linspace(0, N*dt, N+1)
u_e = I*np.exp(-a*t) # exact solution, I and a are global
u = u_e # naming convention when writing up the scheme
R = np.zeros(N)
for n in range(0, N):
R[n] = (u[n+1] - u[n])/dt + a*u[n]
# Theoretical expression for the trunction error
R_a = 0.5*I*(-a)**2*np.exp(-a*t)*dt
return R, t[:-1], R_a[:-1]
if __name__ == '__main__':
I = 1; a = 2 # global variables needed in decay_FE
trunc_empir.estimate(decay_FE, T=2.5, N_0=6, m=4, makeplot=True)

Xet Storage Details

Size:
734 Bytes
·
Xet hash:
eaa09f614ebf6e377375de3a5323fbbe858f9dcef550abdec2f0d8db1994cd1e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.