Posted By

iamok on 05/06/09


Tagged

math sin wave


Versions (?)

generate periodic sin


 / Published in: Python
 

  1. def generateSin(amplitude,frequency,phase,x):
  2. return [x,amplitude * math.sin(x * frequency + phase)]
  3.  
  4. print [generateSin(10, 1, 0, x) for x in range(10)]
  5. '''
  6. [[0, 0.0], [1, 8.4147098480789655], [2, 9.0929742682568175], [3, 1.4112000805986722], [4, -7.5680249530792825], [5, -9.5892427466313848], [6, -2.7941549819892586], [7, 6.5698659871878906], [8, 9.8935824662338181], [9, 4.1211848524175663]]
  7. '''
  8. #this will flatten the list
  9. print sum([generateSin(10, 1, 0, x) for x in range(10)],[])
  10. '''
  11. [0, 0.0, 1, 8.4147098480789655, 2, 9.0929742682568175, 3, 1.4112000805986722, 4, -7.5680249530792825, 5, -9.5892427466313848, 6, -2.7941549819892586, 7, 6.5698659871878906, 8, 9.8935824662338181, 9, 4.1211848524175663]
  12. '''

Report this snippet  

You need to login to post a comment.