Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import log, e, sqrt, exp
- import numpy as np
- import matplotlib.pyplot as plt
- def func(x, y):
- return exp(x + y)
- h = 0.005
- a = 0
- b = 0.5
- y0 = 0
- x = np.arange(a + h, b + h, h)
- y = []
- y.append(y0)
- for xn, n in zip(x, range(len(x))):
- f1 = func(xn, y[n])
- f2 = func(xn + h / 2, y[n] + (h / 2) * f1)
- f3 = func(xn + h, y[n] - h * f1 + 2 * h * f2)
- y.append(y[n] + (h / 6) * (f1 + 4 * f2 + f3))
- x = x.tolist()
- x.insert(0, 0)
- plt.plot(x, y)
- plt.tick_params(length=4, width=2, labelsize=10)
- r = [i for i in np.arange(0, 1.5, 0.1)]
- plt.yticks(r)
- plt.xticks(r)
- plt.grid(True)
- # plt.show()
- for i, j in zip(x, y):
- print('x: ', round(i, 5), ' ', 'y: ', round(j, 5), sep=' ')
- # def solv(func, a, b, h, y0, x0):
- # # valid(a, b, h, y0, x0)
- # x = np.arange(a+h, b+h, h)
- # y = []
- # y.append(y0)
- # for xn,n in zip(x,range(len(x))):
- # f1 = func(xn, y[n])
- # f2 = func(xn + h/2, y[n] + (h/2)*f1)
- # f3 = func(xn + h, y[n] - h*f1 + 2*h*f2)
- # y.append(y[n] + (h/6)*(f1 + 4*f2 + f3))
- # x = x.tolist()
- # x.insert(0, 0)
- # plt.plot(x, y)
- # plt.tick_params( length=4, width=2, labelsize=10)
- # r = [i for i in np.arange(0, 1.5,0.1)]
- # plt.yticks(r)
- # plt.xticks(r)
- # plt.grid(True)
- # # plt.show()
- # return round(y[int((x0 - a)*(1/h))], 5)
- # print(solv(func, 0, 0.5, 0.0001, 0, 0.5))
- # print(-log(2 - exp(0.5)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement