Advertisement
Kribo

Bryting-NN-4

Aug 4th, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. #Definere funksjonar for utrekning av bølgjene:
  5. def f(A,k,x,c):
  6.     return A*np.sin(k*x+c)
  7.  
  8. def g(A2,k2,x,c2):
  9.     return A2*np.sin(k2*x+c2)
  10.  
  11. #Få data frå brukaren:
  12. A = float(input("Skriv inn verdi for A: "))
  13. k = float(input("Skriv inn verdi for k: "))
  14. c = float(input("Skriv inn verdi for c: "))
  15.  
  16. A2 = float(input("Skriv inn verdi for A2: "))
  17. k2 = float(input("Skriv inn verdi for k2: "))
  18. c2 = float(input("Skriv inn verdi for c2: "))
  19.  
  20. #Bølgjene kvar for seg:
  21. fig = plt.figure()
  22. ax1 = fig.add_subplot(111)
  23. ax1.grid(True)
  24.  
  25. x = np.linspace(0, 8*np.pi, 1000)
  26. plt.ylim(-10,10)
  27.  
  28. ax1.plot(x,f(A,k,x,c))
  29. ax1.plot(x,g(A2,k2,x,c2))
  30.  
  31. #Bølgjene overlagra:
  32. fig = plt.figure()
  33. ax2 = fig.add_subplot(111)
  34. ax2.grid(True)
  35.  
  36. x = np.linspace(0, 8*np.pi, 1000)
  37. plt.ylim(-10,10)
  38.  
  39. ax2.plot(x,f(A,k,x,c)+g(A2,k2,x,c2))
  40. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement