fork download
  1. import math
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from scipy.integrate import odeint
  5.  
  6. g = 9.81
  7. l = 0.5
  8.  
  9.  
  10. def f(y, t):
  11. x, vx = y
  12. return [vx, (-1) * g / l * (x - (x ** 3) / 6)]
  13.  
  14.  
  15. t = np.linspace(0, 50, 10000)
  16.  
  17. X0 = [0, 0]
  18. x, vx = odeint(f, X0, t, full_output=False).T
  19.  
  20.  
  21. Amplituda=[]
  22. Chastota=[]
  23.  
  24.  
  25. '''
  26. def AH(nach, konec):
  27. N = 100
  28. dx = (konec - nach) / N
  29. fi = nach
  30. while fi < konec:
  31. t = np.linspace(0, 50, 10000)
  32. X0 = [fi, 0]
  33. x, vx = odeint(f, X0, t, full_output=False).T
  34. j = 0
  35. t_posled = 0
  36. Amplituda1=[]
  37. Chastota1=[]
  38. for i in xrange(0, 10000):
  39. if i > 0 and x[i - 1] * x[i] < 0:
  40. j += 1
  41. t_posled = 50. / 10000 * i
  42. np.append.Amplituda1 = fi
  43. np.append.Chastota1 = t_posled / j * 2
  44. fi += dx
  45. return Amplituda1, Chastota1
  46. '''
  47. N = 100
  48. konec=math.pi / 2
  49. nach=math.pi / 100
  50. dx = (konec - nach) / N
  51. fi = nach
  52. Amplituda1 = []
  53. Chastota1 = []
  54. while fi < konec:
  55. X0 = [fi, 0]
  56. x, vx = odeint(f, X0, t, full_output=False).T
  57. j = 0
  58. t_posled = 0
  59. for i in xrange(0, 10000):
  60. if i > 0 and x[i - 1] * x[i] < 0:
  61. j += 1
  62. t_posled = 50. / 10000 * i
  63. np.append.Amplituda1 = fi
  64. np.append.Chastota1 = j / t_posled / 2
  65. fi += dx
  66.  
  67.  
  68. #Amplituda, Chastota = AH(math.pi / 100, math.pi / 2)
  69.  
  70. fig = plt.figure(facecolor='white')
  71. plt.plot(Chastota1, Amplituda1)
  72. plt.grid(True)
  73. plt.show()
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: '.' expected
import math
           ^
Main.java:2: error: ';' expected
import matplotlib.pyplot as plt
      ^
Main.java:2: error: class, interface, or enum expected
import matplotlib.pyplot as plt
                 ^
Main.java:2: error: class, interface, or enum expected
import matplotlib.pyplot as plt
                  ^
Main.java:3: error: '.' expected
import numpy as np
            ^
Main.java:3: error: ';' expected
import numpy as np
               ^
Main.java:4: error: '.' expected
from scipy.integrate import odeint
                                  ^
Main.java:6: error: ';' expected
g = 9.81
 ^
Main.java:45: error: unclosed character literal
fig = plt.figure(facecolor='white')
                           ^
Main.java:45: error: unclosed character literal
fig = plt.figure(facecolor='white')
                                 ^
10 errors
stdout
Standard output is empty