(Writing to a file). A damped sine wave is a sinusoidal function whose amplitude
ID: 3575968 • Letter: #
Question
(Writing to a file). A damped sine wave is a sinusoidal function whose amplitude approaches zero as time increases.
Y(t)= e^-t (sin(2pit))
Write a program that will generate a data file containing 100 data points using the damped sine function above. Use the following formula for time:
Where 1 k 100.
Each record in your file will have two fields, time and the value of Y(t). Save your file with the name damped_sinusoidal.txt.
You can make use of the following math library functions:
sin(x) -> returns the sine of a radian angle x.
exp(x) -> returns the value of e raised to the xth power.
Program must be written in C. Thanks!
Explanation / Answer
#include<stdio.h>
#include<math.h>
#define PI 3.14
int main(){
float k, t, s, e;
FILE *fp;
fp = fopen("sindata.txt", "w");
for(k=1;k<=100;k++){
t = (k-1)/10;
s = sin(2 * PI * t);
e = exp( - t * s); //use this if the formula states whole -t * sin(2 * PI * t) raise to e
//e = exp(-t) * s;
fprintf(fp, "%f %f ", t, e);
}
fclose(fp);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.