KgCro

zlatni rez

Oct 29th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import scipy.optimize as opt
  4.  
  5. def A(r):
  6.     V = 0.2
  7.     return 2*r**2*np.pi + 2*V/r
  8.  
  9. def gs(f, xl, xd, eps):
  10.     psi = (np.sqrt(5)+1)/2
  11.     yl, yd = f(xl), f(xd)
  12.     xul = xl + ratio*(xd-xl)
  13.     xud = xd - ratio*(xd-xl)
  14.     yul, yud = f(xul), f(xud)
  15.    
  16.     eps = 0.05
  17.     err = 1
  18.     maxit = 100
  19.     it = 0
  20.     while it < maxit and err > eps: #greska veca od prihvatljive greske
  21.         it += 1
  22.         if yul < yud:
  23.             xl = xl
  24.             xd = xud
  25.         else:
  26.             xd = xd
  27.             xl = xul
  28.         xul = xl + ratio*(xd-xl)
  29.         xud = xd - ratio*(xd-xl)
  30.         yul, yud = f(xul), f(xud)
  31.         err = np.abs(xud - xul)
  32.    
  33.     return (xul + xud)/2
  34.  
  35. rmin, rmax = 0.05, 1.5
  36. r = np.linspace(rmin, rmax, 200)
  37. a = A(r)
  38.    
  39. plt.plot(r, a, color = 'salmon', lw = 2, ls = '-')
  40. plt.xlabel('polumjer [m]')
  41. plt.ylabel('povrsina lima')
  42. plt.title('optimalni dizajn sic!')
  43. plt.grid()
  44. plt.savefig('zlatni_rez.png') #sejvanje
  45. plt.show()
Add Comment
Please, Sign In to add comment