Advertisement
Guest User

Untitled

a guest
Feb 14th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import math
  2.  
  3. def fun(a,b,c,d,x):
  4.      return a * x + b * math.sqrt(x ** 3) - c * math.exp(-x / 50.0) - d
  5.  
  6.  
  7. a = 0.59912051
  8. b = 0.64030348
  9. c = 263.33721367
  10. d = 387.92069617
  11.  
  12. x1 = 0.0
  13. x2 = 100.0
  14.  
  15. check = 1
  16.  
  17. ShouldBe = 73.595368554162
  18.  
  19. while True:
  20.     xmiddle = (x1+x2)/2.0
  21.     fmid = fun(a,b,c,d,xmiddle)
  22.     ans1 = fun(a,b,c,d,x1)
  23.     ans2 = fun(a,b,c,d,x2)
  24.     ansm = fun(a,b,c,d,xmiddle)
  25.     check = (int)(fmid * 100000000)
  26.     if check == 0:
  27.         break
  28.     if abs(ans1) < abs(ans2):
  29.         x2 = xmiddle
  30.     else:
  31.         x1 = xmiddle
  32.  
  33. print(xmiddle)
  34. print(ShouldBe)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement