Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Adams():
- flag = 0
- N = 10
- help_err = 0
- plt.xlabel('x')
- plt.ylabel('y')
- while True:
- step = (B - A) / (N - 1)
- u_help = np.empty(N)
- arr_err = np.empty(N)
- u_help[0] = 0
- u_help[1] = u_help[0] + step * g(0, u_help[0])
- u_help[2] = u_help[1] + step * g(step * 1, u_help[1])
- arr_err[0] = 0
- error = 0
- for i in range(3, N):
- a_1 = g(step * (i - 3), u_help[i - 3])
- a_2 = 5 * g(step * (i - 2), u_help[i - 2])
- a_3 = 19 * g(step * (i - 1), u_help[i - 1])
- f_non_lin = y - u_help[i - 1] - (step / 24) * (a_3 - a_2 + a_1) - (9 / 24) * step * (1 / (i * step + 2) + p * pow((y - phi_3(i * step)), 5))
- f_n_l = lambdify(y, f_non_lin)
- der_f_n_l = f_non_lin.diff(y)
- deriv = lambdify(y, der_f_n_l)
- y_0, e = phi_3(i * step), 0.001
- while np.fabs(f_n_l(y_0)) > e:
- y_0 = y_0 - f_n_l(y_0) / deriv(y_0)
- u_help[i] = y_0
- if error < np.fabs(np.double(u_help[i]) - np.double(phi_3(i * step))):
- error = np.fabs(u_help[i] - phi_3(i * step))
- if error < eps:
- flag = 1
- print(error, end = '\t')
- if help_err != 0:
- print("p = ", np.log2(help_err / error))
- help_err = error
- a = np.linspace(A, B, 160)
- b = phi_3(a)
- plt.grid()
- plt.plot(a, b, 'r')
- c = np.linspace(A, B, N)
- plt.plot(c, arr_err, 'g')
- plt.plot(c, u_help, 'b')
- plt.pause(5)
- if flag == 1:
- break
- N = 2 * N
- plt.show()
- return u_help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement