Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. def my_iteration(n, x0, y0):
  5. func1 = lambda x, y: math.tan(x * y + 0.5) - x ** 2
  6. deriv1x = lambda x, y: y / (math.cos(x * y + 0.5) ** 2) - 2 * x
  7. deriv1y = lambda x, y: x / (math.cos(x * y + 0.5) ** 2)
  8. func2 = lambda x, y: x ** 2 + y ** 2 - 1
  9. deriv2x = lambda x, y: 2 * x
  10. deriv2y = lambda x, y: 2 * y
  11. matrix = [[0, 0], [0, 0]]
  12. with open("output.txt", "w") as file:
  13. for i in range(0, n):
  14. matrix[0][0] = deriv2y(x0, y0)
  15. matrix[1][0] = -deriv2x(x0, y0)
  16. matrix[0][1] = -deriv1y(x0, y0)
  17. matrix[1][1] = deriv1x(x0, y0)
  18. det = matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]
  19. for k in range(2):
  20. for j in range(2):
  21. matrix[k][j] /= det
  22. f = [0, 0]
  23. f[0] = func1(x0, y0)
  24. f[1] = func2(x0, y0)
  25. x0 -= matrix[0][0] * f[0] + matrix[0][1] * f[1]
  26. y0 -= matrix[1][0] * f[0] + matrix[1][1] * f[1]
  27. file.write(str(i) + " : " + str(x0) + " " + str(y0) + "\n")
  28.  
  29.  
  30. my_iteration(20, 1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement