def dydx(x, y):
return 2 - y / x
x0 = 1
y0 = 2
xend = 2
x= x0
y= y0
dt = 0.001
t = (xend - x0) / dt
for i in range(int(t)):
y = y + dt * dydx(x, y)
x = x + dt
print(y)
2.499749874937434
This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.
More than 3 years have passed since last update.
def dydx(x, y):
return 2 - y / x
x0 = 1
y0 = 2
xend = 2
x= x0
y= y0
dt = 0.001
t = (xend - x0) / dt
for i in range(int(t)):
y = y + dt * dydx(x, y)
x = x + dt
print(y)
2.499749874937434
Register as a new user and use Qiita more conveniently