Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. a=1
  5. x0=5
  6. L=10
  7. J=101
  8. cf= 0.5
  9. u = []
  10. un = []
  11.  
  12. #definisco gaussiana
  13. def gaussian(a, b):
  14.     return np.exp(-np.power(a-b,2))
  15.  
  16.  
  17. #calcolo vettore x
  18. deltax= L/(J-1)
  19. x_val= np.arange(0,L,deltax)
  20.  
  21. #calcolo vettore u
  22. for i in x_val:
  23.     u.append(gaussian(i,x0))
  24.  
  25.  
  26. #salvo gaussiana statica
  27. plt.plot(x_val,u)
  28. plt.savefig("staticgaussian.png")
  29.  
  30. deltat= (deltax * cf)/a
  31.  
  32. for j in range(0,len(u)):
  33.     if j==0:
  34.         umin=-1
  35.         umax=j+1
  36.        
  37.     if j==J-1:
  38.         umin=j-1
  39.         umax=0
  40.     else:
  41.         umin=j-1
  42.         umax=j+1
  43.  
  44.     # val= 0.5*( (u[umin]) + (u[umax]) ) - ( (a*deltat)/(2*deltax) )*( (u[umax]) - (u[umin]) )
  45.     # un.append(val)
  46.     print(j)
  47.  
  48. print(un)
  49. #plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement