Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def fun(a,b,c,d,x):
- return a * x + b * math.sqrt(x ** 3) - c * math.exp(-x / 50.0) - d
- a = 0.59912051
- b = 0.64030348
- c = 263.33721367
- d = 387.92069617
- x1 = 0.0
- x2 = 100.0
- check = 1
- ShouldBe = 73.595368554162
- while True:
- xmiddle = (x1+x2)/2.0
- fmid = fun(a,b,c,d,xmiddle)
- ans1 = fun(a,b,c,d,x1)
- ans2 = fun(a,b,c,d,x2)
- ansm = fun(a,b,c,d,xmiddle)
- check = (int)(fmid * 100000000)
- if check == 0:
- break
- if abs(ans1) < abs(ans2):
- x2 = xmiddle
- else:
- x1 = xmiddle
- print(xmiddle)
- print(ShouldBe)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement