高斯-勒让德公式 求积分

 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 }

 

转载于:https://www.cnblogs.com/liugl7/p/4963500.html

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值