Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bisekcja(a0, b0, eps, alfa):
- a = []
- b = []
- s = []
- a.append(a0)
- b.append(b0)
- while abs(a[-1]-b[-1]) > eps and len(s) < 10000:
- #s.append((a[-1]+b[-1])/2)
- s.append(a[-1] +((b[-1]-a[-1])*alfa))
- if f(s[-1])*f(a[-1]) < 0:
- a.append(a[-1])
- b.append(s[-1])
- else:
- a.append(s[-1])
- b.append(b[-1])
- plt.figure(1, figsize=(8,8))
- plt.plot(a)
- plt.plot(b)
- plt.figure(2, figsize=(8,8))
- x = np.linspace(a0,b0, 30)
- plt.plot(x,f(x))
- plt.scatter(s,f(s), c=range(len(s)), cmap=plt.get_cmap('Reds'))
- plt.xlim([a0, b0])
- print(len(s))
- return s[-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement