高斯-勒讓德公式 求積分

來源:互聯網
上載者:User

標籤:

 1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 //計算f(x)=1/x 在[1,3]上的積分  5  6 double f(double x){ 7     return 1.0/(x+2); 8 } 9 10 double f1(double x){11     return 1.0/(x+5);12 }13 double f2(double x){14     return 1.0/(x+7); 15 }16 17 double f3(double x){18     return 1.0/(x+9);19 }20 double f4(double x){21     return 1.0/(x+11); 22 }23 24 int main(){25     //運用三點高斯公式積分值 26     printf("%2.8f\n",    (0.5555556*f( -0.7745967)+0.8888889*f( 0 )+0.5555556*f( 0.7745967) ));27 28     //運用五點高斯公式求積分值 29     printf("%2.8f\n",  0.2369269*f(-0.9061799)+ 0.2369269*f(0.9061799)+0.4786287*f(-0.5384693)+0.4786287*f(0.5384693) +30     0.5688889*f(0) );31     printf("\n");32     33     //將區間4等分,分別利用二點高斯公式,然後累加得積分值 34         printf("%2.8f\n",f1( -1.0/sqrt(3.0))+f1(1.0/sqrt(3.0))  );35         printf("%2.8f\n",f2( -1.0/sqrt(3.0))+f2(1.0/sqrt(3.0))  );    36         printf("%2.8f\n",f3( -1.0/sqrt(3.0))+f3(1.0/sqrt(3.0))  );37         printf("%2.8f\n",f4( -1.0/sqrt(3.0))+f4(1.0/sqrt(3.0))  );38             39         printf("sum=%2.8f\n",f1( -1.0/sqrt(3.0))+f1(1.0/sqrt(3.0)) +f2( -1.0/sqrt(3.0))+f2(1.0/sqrt(3.0)) +f3( -1.0/sqrt(3.0))+f3(1.0/sqrt(3.0)) +f4( -1.0/sqrt(3.0))+f4(1.0/sqrt(3.0))  );40             41 }

 

高斯-勒讓德公式 求積分

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.