Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- z2i = 600
- z1i = 500
- z2f = 1000
- Dt2 = 300
- Dt1 = 350
- z2 = np.linspace(z2i,z2f,11)
- z1 = np.zeros(11)
- for i in range(11):
- z1[i] = z1i-((Dt2/Dt1)**2)*(z2[i]-z2i)
- #sampai sini nilai z1 dan z2 sudah diketahui semua
- tol=1e-4
- xold=200
- D=4
- rho=1
- myu=0.01
- Le=2e4
- g=981
- #Subroutine 1: F(x)
- def fungsi(xi):
- v=xi
- Q=np.pi/4*D**2*v
- Hm=3718.5-2.3496*Q+7.8474e-4*Q**2-9.5812e-8*Q**3
- Re=rho*v*D/myu
- f=0.0596/(Re**0.215)
- F=600-500+f*Le*v**2/(2*g*D)-Hm # ini masukin z2 z1 nya manual soalnya ak nga bisa nge loop nya
- return F
- def dfungsi(xi):
- eps = 1e-5
- fplus = fungsi(xi+eps)
- fmin = fungsi(xi-eps)
- dfxi = (fplus-fmin)/(2*eps)
- return dfxi
- tol = 0.01
- iterasi = 1
- xold = 200
- fold = fungsi(xold)
- dfold = dfungsi(xold)
- x = np.array([xold])
- fx = np.array([fold])
- xnew = xold - fold/dfold
- ea = abs((xnew-xold)/(xnew))*100
- while ea >= tol:
- iterasi += 1
- xold = xnew
- fold = fungsi(xold)
- dfold = dfungsi(xold)
- x = np.append(x,xold)
- fx = np.append(fx,fold)
- xnew = xold-(fold/dfold)
- ea = abs((xnew-xold)/(xnew))*100
- fnew = fungsi(xnew)
- satuperv = 1/xnew
- tabel=np.zeros([11,5])
- tabel[:,0]= z2
- tabel[:,1]= z1
- tabel[:,2]= xnew
- tabel[:,3]= fnew
- tabel[:,4]= satuperv
- header = ['z2 ', 'z1' , 'v' , 'f(v)' , '1/v']
- garis = 55*('_')
- print(garis)
- print('{:^1s} {:^15s} {:^5s} {:^15s} {:^13s}'.format(*header))
- print(garis)
- for baris in tabel:
- print('{:>1.2f}{:>10.3f}{:>10.2f}{:>15e}{:>15e}'.format(*baris))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement