In [4]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
tmax = 10.0 M = 100 t = np.linspace(0, tmax, M) t
In [6]:
tmax = 10.0
M = 100
t = np.linspace(0, tmax, M)
t
Out[6]:
In [3]:
h = t[1]-t[0]
print('h =', h)
In [4]:
N = 2
y = np.zeros((M,N))
print('N =', N)
print('M =', M)
print('y.shape =', y.shape)
In [1]:
from scipy.integrate import odeint
In [7]:
def solve_euler(derivs, y0, x):
y = np.empty_like(x)
y[0]= y0
h = x[1] - x[0]
for n in range(0, len(x)-1):
y[n+1] = y[n] +h*derivs(y[n], x[n])
return y
In [11]:
x = np.linspace(0, 1.0, 11)
y = np.empty_like(x)
y0 = y[0]
def derivs(y, x):
return x+2*y
plt.plot(solve_euler(derivs, y0, x), color='orange')
Out[11]:
In [ ]: