用C语言实现梯形积分法并行,c - 用C语言中的梯形规则进行双积分 - SO中文参考 - www.soinside.com...

我试图实现一个程序,我可以用梯形法则计算一个双积分作为x和y的函数(这是我最了解的那个)。但是,除了没有得到结果之外,我希望程序对于非常大的n个范围具有非常大的计算时间。

我首先想到的是计算函数关于y的积分,然后在程序的主体中它根据所提出的参数调用它并计算它在x函数中的值,但它不能很好地工作,我想不出办法做到这一点。

有人可以帮助我正确,更有效地实施该计划吗?

这是我做的代码:

#include

#include

double f(double x, double y, double ay,double by, double ny);

int main()

{

int i;

int nx = 0;

double ax, bx;

double sumx = 0;

double soma=0;

double hx,hy;

double x,y;

double ay,by;

int ny;

printf("inferior limit ax = ");

scanf("%lf", &ax);

printf("upper limit bx (b>a) = ");

scanf("%lf", &bx);

printf("interval nx (n>1) n = ");

scanf("%d", &nx);

hx = (bx - ax) / (nx - 1);

x = ax;

printf("inferior limit ay = ");

scanf("%lf", &ay);

printf("upper limit by (b>a) = ");

scanf("%lf", &by);

printf("interval ny (n>1) n = ");

scanf("%d", &ny);

for (i = 1; i <= nx - 1; i++)

{

sumx = sumx + f(x,y,ay,by,ny) + f(x + hx,y,ay,by,ny);

x = x + hx;

}

sumx = sumx * (hx / 2);

printf("O resultado da soma e': %lf\n", sumx);

return 0;

} // end main()

//

//

//

double f(double x, double y, double ay,double by, double ny)

{

double func;

int j=0;

double hy;

double sumy=0;

func= sin(x+y) / ((x*x) + y);

hy = (by - ay) / (ny -1);

y= ay;

for (j =1; j <= ny - 1; j++)

{

sumy = sumy + sin(x + (y + hy)/ (x*x) + y+ hy);

y = y +hy;

}

return sumy = sumy * (hy / 2);

} // end f()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值