Guest User

Untitled

a guest
Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. from scipy.sparse import diags
  5. def Laasonen(dt,dy,t_max,y_max,k,T1,T2):
  6. s = k*dt/dy**2
  7. y = np.arange(0,y_max+dy,dy)
  8. t = np.arange(0,t_max+dt,dt)
  9. nt = len(t)
  10. ny = len(y)
  11. T = np.zeros((ny,))
  12. T[0] = T1
  13. T[-1] = T2
  14. A = diags([-s, 1+2*s, -s], [-1, 0, 1], shape=(ny-2, ny-2)).toarray()
  15. for n in range(nt):
  16. Tn = T
  17. B = Tn[1:-1]
  18. B[0] = B[0]+s*T1
  19. B[-1] = B[-1]+s*T2
  20. T[1:-1] = np.linalg.solve(A,B)
  21. return y,t,T,s
  22.  
  23. dt = 0.01
  24. dy = 0.0005
  25. k = 10**(-4)
  26. y_max = 0.04
  27. T1 = 100
  28. T2 = 0
  29.  
  30. for time in np.linspace(0,1.0,10):
  31. y,t,T,s = Laasonen(dt,dy,time,y_max,k,T1,T2)
  32. plt.plot(y,T)
Add Comment
Please, Sign In to add comment