用gnuplot画出c产生数据的波形图
生活随笔
收集整理的這篇文章主要介紹了
用gnuplot画出c产生数据的波形图
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- 數(shù)據(jù)
- 代碼
- 畫(huà)圖
- 問(wèn)題
- 修正
數(shù)據(jù)
用c產(chǎn)生表達(dá)式為:
s(t)=sin(pit)+2cos(pit)的數(shù)據(jù),輸出為t跟s。
代碼
#include<stdio.h> #include<math.h> #define pi 3.14 int main() {double s;for (int t=0; t<10; t++)//十秒的數(shù)據(jù){s=sin(pi*t)+2*cos(pi*t);printf("%d\t%f\n",t,s);} }產(chǎn)生的數(shù)據(jù)是
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
畫(huà)圖
1.要先在DOS打開(kāi)編譯的程序
結(jié)果如圖
先打開(kāi)的原因是因?yàn)橹坝胓nuplot找不到數(shù)據(jù)。
2.接著打開(kāi)gnuplot
3.輸入文件名plot “<1.exe” w l
過(guò)程
結(jié)果圖
問(wèn)題
數(shù)據(jù)太少。
修正
代碼為
#include<stdio.h> #include<math.h> #define pi 3.14 int main() {double t,s;for (int i=0; i<8000; i++)//4秒,產(chǎn)生更多數(shù)據(jù){t=i/2000.0;s=sin(pi*t)+cos(2*pi*t);printf("%e\t%e\n",t,s);} }結(jié)果圖
總結(jié)
以上是生活随笔為你收集整理的用gnuplot画出c产生数据的波形图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux centos 7定时任务添加
- 下一篇: 编写jmeter测试用例_Jmeter