Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 10th, 2013, 03:17 AM
 kostenftw
Registered User

Join Date: Nov 2012
Posts: 6
Time spent in forums: 1 h 40 m 34 sec
Reputation Power: 0
Sine wave plotted in file

represent a sine
wave with a period of 20ms.

this has to be representet in numbers, plottet into a file, and it has to be in a function sine(), but most of all i need help how to generate the numbers for the sine signal? :P

#2
January 10th, 2013, 05:47 AM
 verstapp
Registered User

Join Date: Nov 2012
Posts: 6
Time spent in forums: 14 h 1 m 41 sec
Reputation Power: 0
very simplistically:

Code:
#vary parameters to get the amplitude/wavelength you want.
import math
plotend=2*math.pi
l=[]
x=0
while x<plotend:
l.append(math.sin(x))
x+=0.01
#print l to file

#3
January 16th, 2013, 04:37 AM
 kostenftw
Registered User

Join Date: Nov 2012
Posts: 6
Time spent in forums: 1 h 40 m 34 sec
Reputation Power: 0
Quote:
 Originally Posted by verstapp very simplistically: Code: #vary parameters to get the amplitude/wavelength you want. import math plotend=2*math.pi l=[] x=0 while x

it somewhat helps, but i cant really figure out how to implement it, i want to be able to yield one number at the time and plot it into a file, where every line in the file is a ms in time

#4
January 16th, 2013, 09:59 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,145
Time spent in forums: 1 Month 3 Weeks 2 Days 7 h 32 m 29 sec
Reputation Power: 455
You could replace
l.append(math.sin(x))
with
print(math.sin(x))
or even
print('%g %g'%(x,math.sin(x)))

then run python on the command line redirect stdout to a file. Yes, it ought to work in DOS.

shell_prompt> python my_program.py > sinusoid.dat
__________________
[code]Code tags[/code] are essential for python code!

#5
January 29th, 2013, 10:50 PM
 Dietrich
Contributing User

Join Date: Feb 2005
Posts: 574
Time spent in forums: 5 Days 4 h 6 m 36 sec
Reputation Power: 63
Is there a relationship between x in sine(x) and time?
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Sine wave plotted in file