Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import scipy.optimize as opt
- def A(r):
- V = 0.2
- return 2*r**2*np.pi + 2*V/r
- def gs(f, xl, xd, eps):
- psi = (np.sqrt(5)+1)/2
- yl, yd = f(xl), f(xd)
- xul = xl + ratio*(xd-xl)
- xud = xd - ratio*(xd-xl)
- yul, yud = f(xul), f(xud)
- eps = 0.05
- err = 1
- maxit = 100
- it = 0
- while it < maxit and err > eps: #greska veca od prihvatljive greske
- it += 1
- if yul < yud:
- xl = xl
- xd = xud
- else:
- xd = xd
- xl = xul
- xul = xl + ratio*(xd-xl)
- xud = xd - ratio*(xd-xl)
- yul, yud = f(xul), f(xud)
- err = np.abs(xud - xul)
- return (xul + xud)/2
- rmin, rmax = 0.05, 1.5
- r = np.linspace(rmin, rmax, 200)
- a = A(r)
- plt.plot(r, a, color = 'salmon', lw = 2, ls = '-')
- plt.xlabel('polumjer [m]')
- plt.ylabel('povrsina lima')
- plt.title('optimalni dizajn sic!')
- plt.grid()
- plt.savefig('zlatni_rez.png') #sejvanje
- plt.show()
Add Comment
Please, Sign In to add comment