Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.animation as animation
  4. n = input()
  5. m = input()
  6. def getModel(dt , d , delt):
  7. grid = np.zeros((n , m))
  8. for i in range(0 , m):
  9. grid[0][i] = grid[n-1][i] = 100
  10. for i in range(1 , n - 1):
  11. grid[i][0] = 10
  12. grid[i][m-1] = 10
  13. t = 0
  14. # print grid
  15. while(t < 10):
  16. tend = np.array((n , m))
  17. tend = grid
  18. for i in range(1 , n-1):
  19. for j in range(1 , m -1):
  20. tend[i][j] = grid[i][j]+ (dt*d/delt/delt)*(grid[i + 1][j] + grid[i - 1][j] + grid[i][j + 1]+grid[i][j-1]-4*grid[i][j])
  21. t += dt
  22. #nexbin(grid)
  23. def update(i):
  24. matrice.set_array(grid)
  25.  
  26. fig, ax = plt.subplots()
  27. matrice = ax.matshow(grid)
  28. plt.colorbar(matrice)
  29.  
  30. animation.FuncAnimation(fig, update)
  31. plt.show()
  32. grid = tend
  33. #plt.show(block=True)
  34.  
  35. getModel(0.01,30,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement