Facebook
From Unique Owl, 8 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 347
  1.  
  2. import math
  3.  
  4. def calculateOscillator():
  5.         result = open('result.txt', 'w')
  6.  
  7.         print 'Podaj przedzial czasowy:'
  8.         time = float(raw_input())
  9.  
  10.         print 'Podaj krok czasowy:'
  11.         krok = float(raw_input())
  12.  
  13.         print 'Podaj mase oscylatora:'
  14.         masa = float(raw_input())
  15.  
  16.         print 'Podaj stala sprezystosci:'
  17.         k = float(raw_input())
  18.  
  19.         print 'Podaj C1 oscylatora 1:'
  20.         c1 = float(raw_input())
  21.  
  22.         print 'Podaj C2 oscylatora 1:'
  23.         c2 = float(raw_input())
  24.  
  25.         print 'Podaj C1 oscylatora 2:'
  26.         c3 = float(raw_input())
  27.  
  28.         print 'Podaj C2 oscylatora 2:'
  29.         c4 = float(raw_input())
  30.  
  31.         omega = math.sqrt(k/masa)
  32.         A1 = math.sqrt(c1*c1 + c2*c2)
  33.         A2 = math.sqrt(c3*c3 + c4*c4)
  34.  
  35.         i = 0;
  36.         while i < time:
  37.                 xt = A1*math.cos(omega * i - (c2/c1))
  38.                 yt = A2*math.cos(omega * i - (c4/c3))
  39.                 result.write(str(xt) + ' ' + str(yt) + '\n')
  40.                 i += krok
  41.  
  42.  
  43. if __name__ == "__main__":
  44.     calculateOscillator()