Advertisement
Guest User

Untitled

a guest
Oct 25th, 2020
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import math
  2. from dataclasses import dataclass
  3.  
  4.  
  5. @dataclass
  6. class Approximate:
  7.  
  8. ai: float; af: float
  9. da: float; n : int
  10.  
  11. # Default values
  12. aa: float = 0
  13. ei: float = -1
  14. a : float = 0
  15. e : float = 0
  16. i : int = 0
  17.  
  18. done: bool = False
  19. stop: bool = False
  20.  
  21. def step(self):
  22.  
  23. if (self.ei < 0) or (self.ei > self.e):
  24.  
  25. self.ei = self.e
  26. self.aa = self.a
  27.  
  28. if (self.stop):
  29.  
  30. self.i += 1
  31.  
  32. if (self.i >= self.n):
  33.  
  34. self.done = True
  35. self.a = self.aa
  36.  
  37. return # Max iter
  38.  
  39. # Restrict to window around 'solution'
  40. self.ai = self.aa - self.da
  41. self.af = self.aa + self.da
  42.  
  43. self.a = self.ai
  44.  
  45. # Increase accuracy
  46. self.da *= 0.1
  47. self.ai += self.da
  48. self.af -= self.da
  49.  
  50. self.stop = False
  51.  
  52. else:
  53.  
  54. # Probe some points in [ai,af] with step da
  55. self.a = self.a + self.da
  56.  
  57. if (self.a > self.af):
  58.  
  59. self.a = self.af
  60. self.stop = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement