Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- def func(var):
- value = pow((var-5),2) + 3
- return value
- k = (sqrt(5)+1)/2
- a = int(input('podaj wartosc a: '))
- b = int(input('podaj wartosc b: '))
- if(a>b):
- print('a ma byc mniejsze od b, wiec zostaly zamienione miejscami')
- c = a
- a = b
- b = c
- xL = b - k * (b - a)
- xR = a + k * (b - a)
- epsi = pow(10, -3)
- while (abs((b - a)) > epsi):
- if func(xL)<func(xR):
- b = xR
- xR = xL
- xL = b - k * (b - a)
- else:
- a = xL
- xL = xR
- xR = a + k * (b - a)
- result = float((b-a)/2)
- print('a: ' + str(a))
- print('b: ' + str(b))
- print('minimum tej funkcji jest w punkcie: [' + str(result) + ', ' + str(func(result)) + '] ')
Advertisement
Add Comment
Please, Sign In to add comment