import numpy as np
import matplotlib.pyplot as plt
def f(y, x):
return 1/(x+np.sqrt(x**2+1))-y/np.sqrt(x**2+1)
def EM(f, x, t):
h=t[1]-t[0]
for i in range(len(t)-1):
x[i+1]=x[i]+f(x[i], t[i])*h
return x
if __name__=="__main__":
x_i=0; y_i=0
x_f=1
N=1000
x=np.linspace(x_i, x_f, N)
y=np.zeros(len(x), float)
y[0]=y_i
y=EM(f, y, x)
plt.plot(x, y)
plt.title(r"$\frac{dy}{dx}+\frac{y}{\sqrt{x^2+1}}=\frac{1}{x+\sqrt{x^2+1}}$")
plt.xlabel(r"$x$")
plt.ylabel(r"$y$")
plt.show()