Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def my_iteration(n, x0, y0):
- func1 = lambda x, y: math.tan(x * y + 0.5) - x ** 2
- deriv1x = lambda x, y: y / (math.cos(x * y + 0.5) ** 2) - 2 * x
- deriv1y = lambda x, y: x / (math.cos(x * y + 0.5) ** 2)
- func2 = lambda x, y: x ** 2 + y ** 2 - 1
- deriv2x = lambda x, y: 2 * x
- deriv2y = lambda x, y: 2 * y
- matrix = [[0, 0], [0, 0]]
- with open("output.txt", "w") as file:
- for i in range(0, n):
- matrix[0][0] = deriv2y(x0, y0)
- matrix[1][0] = -deriv2x(x0, y0)
- matrix[0][1] = -deriv1y(x0, y0)
- matrix[1][1] = deriv1x(x0, y0)
- det = matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]
- for k in range(2):
- for j in range(2):
- matrix[k][j] /= det
- f = [0, 0]
- f[0] = func1(x0, y0)
- f[1] = func2(x0, y0)
- x0 -= matrix[0][0] * f[0] + matrix[0][1] * f[1]
- y0 -= matrix[1][0] * f[0] + matrix[1][1] * f[1]
- file.write(str(i) + " : " + str(x0) + " " + str(y0) + "\n")
- my_iteration(20, 1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement