Advertisement
fenvel

Untitled

Mar 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import numpy as np
  2.  
  3. z2i = 600
  4. z1i = 500
  5. z2f = 1000
  6. Dt2 = 300
  7. Dt1 = 350
  8.  
  9. z2 = np.linspace(z2i,z2f,11)
  10. z1 = np.zeros(11)
  11. for i in range(11):
  12.     z1[i] = z1i-((Dt2/Dt1)**2)*(z2[i]-z2i)
  13.  
  14.  
  15. #sampai sini nilai z1 dan z2 sudah diketahui semua
  16.    
  17. tol=1e-4
  18. xold=200
  19. D=4
  20. rho=1
  21. myu=0.01
  22.  
  23. Le=2e4
  24. g=981
  25.  
  26. #Subroutine 1: F(x)
  27. def fungsi(xi):
  28.     v=xi
  29.     Q=np.pi/4*D**2*v
  30.     Hm=3718.5-2.3496*Q+7.8474e-4*Q**2-9.5812e-8*Q**3
  31.     Re=rho*v*D/myu
  32.     f=0.0596/(Re**0.215)
  33.     F=600-500+f*Le*v**2/(2*g*D)-Hm  # ini masukin z2 z1 nya manual soalnya ak nga bisa nge loop nya
  34.     return F
  35.  
  36. def dfungsi(xi):
  37.     eps = 1e-5
  38.     fplus = fungsi(xi+eps)
  39.     fmin = fungsi(xi-eps)
  40.     dfxi = (fplus-fmin)/(2*eps)
  41.     return dfxi
  42.  
  43.  
  44.  
  45. tol = 0.01
  46. iterasi = 1
  47. xold = 200
  48. fold = fungsi(xold)
  49. dfold = dfungsi(xold)
  50. x = np.array([xold])
  51. fx = np.array([fold])
  52. xnew = xold - fold/dfold
  53. ea = abs((xnew-xold)/(xnew))*100
  54.  
  55.  
  56.  
  57. while ea >= tol:
  58.     iterasi += 1
  59.     xold = xnew
  60.     fold = fungsi(xold)
  61.     dfold = dfungsi(xold)
  62.     x = np.append(x,xold)
  63.     fx = np.append(fx,fold)
  64.     xnew = xold-(fold/dfold)
  65.     ea = abs((xnew-xold)/(xnew))*100
  66.     fnew = fungsi(xnew)
  67.     satuperv = 1/xnew
  68.  
  69.  
  70.  
  71.  
  72. tabel=np.zeros([11,5])
  73. tabel[:,0]= z2
  74. tabel[:,1]= z1
  75. tabel[:,2]= xnew
  76. tabel[:,3]= fnew
  77. tabel[:,4]= satuperv
  78. header = ['z2 ', 'z1' , 'v' , 'f(v)' , '1/v']
  79. garis = 55*('_')
  80. print(garis)
  81. print('{:^1s} {:^15s} {:^5s} {:^15s} {:^13s}'.format(*header))
  82. print(garis)
  83. for baris in tabel:
  84.     print('{:>1.2f}{:>10.3f}{:>10.2f}{:>15e}{:>15e}'.format(*baris))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement