Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import math
- def f(x):
- return 1 / math.sqrt(2) * (x - 1) / math.sqrt(x - math.log(x))
- def df(x, y):
- return y / (x - 1) - y ** 3 / (x * x - x)
- a = 0.03
- b = 0.97
- eps = 1.0
- n = 1
- while eps > 0.0001:
- x0 = a
- y0 = f(x0)
- x = []
- y = []
- y2 = []
- h = (b - a) / n
- x.append(x0)
- y.append(y0)
- y2.append(y0)
- for i in range(1, n + 1, 1):
- k1 = h * df(x[-1], y[-1])
- k2 = h * df(x[-1] + h / 2, y[-1] + k1 / 2)
- k3 = h * df(x[-1] + h / 2, y[-1] + k2 / 2)
- k4 = h * df(x[-1] + h, y[-1] + k3)
- y.append(y[-1] + 1 / 6 * (k1 + 2 * k2 + 2 * k3 + k4))
- x.append(x0 + i * h)
- y2.append(f(x[-1]))
- eps = math.fabs(f(b) - y[-1])
- print(f"n = {n},\nh = {h},\neps = {eps},\ny(b) = {y[-1]}")
- plt.plot(x, y, color='red')
- plt.plot(x, y2, color='green')
- plt.show()
- n *= 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement