# Feil i Eulers metode som funksjon av dt for dot x = x cos t import numpy as np import matplotlib.pyplot as plt x0 = 1 tMax = 80 dtl = 10.**(-np.arange(0,6)) e = np.zeros(len(dtl)) k = 0 for dt in dtl: n = int(tMax/dt) t = np.zeros(n) dx = np.zeros(n) x = np.zeros(n) x[0] = x0 for i in range(n-1): t[i+1] = (i+1)*dt dx[i] = np.cos(t[i])*x[i] x[i+1] = x[i] + dx[i]*dt e[k] = x[-1]-x0*np.exp(np.sin(t[-1])) print(dt,k,e[k]) k = k+1 plt.loglog(dtl,abs(e),'o') plt.loglog(dtl,dtl*5) plt.xlabel(r'$\Delta t$') plt.ylabel(r'$F(\Delta t)$') plt.savefig('eulerVariabelDt.pdf') plt.show()