[問題] sin用for迴圈積分
開發平台(Platform): C++
問題(Question):想用for迴圈加上梯形法求sin從0到2PI的積分
預期的正確結果(Expected Output):0
錯誤結果(Wrong Output):0.1309
程式碼(Code):*[m
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n =10^6; //切割10^6等分
float A=0;
const double PI=acos( -1 );
for(int count=0;count<=n;count+=1)
{
A=A+((2*PI/n)*(sin(2*PI/n*count)+sin(2*PI/n*(count+1))))/2;
//梯形面積和=上底sin(2*PI/n*count)+下底sin(2*PI/n*(count+1)乘高2*PI/n除2
}
cout<<A;
system("pause");
return 0;
}
補充說明(Supplement):可是積出來怪怪的
請版上鄉民幫忙解惑
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.216.100
※ 編輯: alan810910 來自: 140.115.216.100 (12/16 10:55)
→
12/16 10:57, , 1F
12/16 10:57, 1F
→
12/16 10:57, , 2F
12/16 10:57, 2F
→
12/16 10:58, , 3F
12/16 10:58, 3F
→
12/16 11:04, , 4F
12/16 11:04, 4F
→
12/16 11:06, , 5F
12/16 11:06, 5F
推
12/16 11:51, , 6F
12/16 11:51, 6F
→
12/16 11:52, , 7F
12/16 11:52, 7F
→
12/16 13:51, , 8F
12/16 13:51, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章