Advertisement
PrincePepper

Untitled

Jan 16th, 2022
822
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. import numpy as np
  3. from scipy.integrate import odeint
  4. from matplotlib import pyplot as plt
  5.  
  6.  
  7. def central_difference(tau, h, u, concentration):
  8.     for i in range(2, 30):
  9.         concentration[i] = concentration[i - 1] - ((tau * u)) / (2 * h) * (
  10.                     concentration[i] - concentration[i - 2])
  11.  
  12.  
  13. h = 0.1
  14. tau = 0.1
  15. u = 4
  16. x = np.arange(0, 6, h)
  17.  
  18. concentration = [0 for i in range(60)]
  19.  
  20. for i in range(30):
  21.     if i < 15:
  22.         concentration[i] = 200
  23.     else:
  24.         concentration[i] = 500
  25. print(concentration)
  26.  
  27. fig, axs = plt.subplots(11)
  28. fig.set_size_inches(7, 20)
  29. t = np.arange(0.1, 1, tau)
  30.  
  31. for j, i in enumerate(t):
  32.     central_difference(i, h, u, concentration)
  33.     print(concentration)
  34.     axs[j].plot(x, concentration)
  35. fig.tight_layout()
  36. plt.show()
  37.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement