数据
用c产生表达式为:
s(t)=sin(pit)+2cos(pit)的数据,输出为t跟s。
代码
#include<stdio.h>
#include<math.h>
#define pi 3.14
int main()
{
double s;
for (int t=0; t<10; t++)//十秒的数据
{
s=sin(pi*t)+2*cos(pi*t);
printf("%d\t%f\n",t,s);
}
}
产生的数据是
0 2.000000
1 -1.998405
2 1.996805
3 -1.995199
4 1.993589
5 -1.991973
6 1.990353
7 -1.988727
8 1.987097
9 -1.985461
画图
1.要先在DOS打开编译的程序
结果如图
先打开的原因是因为之前用gnuplot找不到数据。
2.接着打开gnuplot
3.输入文件名plot “<1.exe” w l
过程
结果图
问题
数据太少。
修正
代码为
#include<stdio.h>
#include<math.h>
#define pi 3.14
int main()
{
double t,s;
for (int i=0; i<8000; i++)//4秒,产生更多数据
{
t=i/2000.0;
s=sin(pi*t)+cos(2*pi*t);
printf("%e\t%e\n",t,s);
}
}
结果图