Created
October 12, 2017 11:22
-
-
Save skhokhlov/8e13536e7d1d0764fcab3678f6c97981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from labs.lab2 import runge | |
def f(x, y): | |
# return y * math.log(y) / x | |
return (y * y + x * y) / (x * x) | |
def adams(h): | |
start = 1 | |
end = 2 | |
length = int(math.fabs(end - start) / h + 1) | |
x = [0] * length | |
y = [0] * length | |
x[0] = start | |
y[0] = 1 | |
trash, y2 = runge(h) | |
for i in range(0, 4): | |
x[i + 1] = x[i] + h | |
y[i] = y2[i] | |
for i in range(4, length): | |
x[i] = x[i - 1] + h | |
y[i] = y[i - 1] + h / 24 * ( | |
55 * f(x[i - 1], y[i - 1]) | |
- 59 * f(x[i - 2], y[i - 2]) | |
+ 37 * f(x[i - 3], y[i - 3]) | |
- 9 * f(x[i - 4], y[i - 4]) | |
) | |
# print(y) | |
return x, y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment