Sawtooth problem

Hey Guys, I just got assigned this problem and dont even know to start doing it. Any help is greatly appericated.

The last sample program (above) generates a sine and a cosine waveform (angle, or perhaps time, in column 2, cosine in column 3 and sine in column 4. Write a program to generate 400 (x,y) points of a sawtooth waveform that repeats every 100 points, with a minimum of 0 and a maximum of 5 (as if it were the output of a 0-5v sawtooth wave from a waveform generator). Let x range from 0 to 1.0, and y range from 0 to 5.0. If you plot your output with excel or matlab, you should get something like this:

Write your output to a file called “sawtooth.txt”. The first few lines of your file should look something like the following. (You do not need to worry about making the columns line up, but if you want to, look up setw( ) and setprecision( ) in the textbook or via googling):

0.0025 0.05
0.005 0.1
0.0075 0.15
0.01 0.2
0.0125 0.25
0.015 0.3
0.0175 0.35
0.02 0.4
0.0225 0.45

Hint: the modulus (%) operator comes in handy here…think about what
i % 100
gives you (assuming you’re using i as a loop counter, from 0-399).
Last edited on
dont even know to start doing it.

The last sample program ...

You have an another program that generates points. All you need to do, is to make sure the x ranges as expected, and that instead of cos(x), you compute y from x in some other way. Your homework includes hints.
Topic archived. No new replies allowed.