1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 写一个用矩形法求定积分的通用公式 分别求 sinx在0-1上积分 cosx在0-1上积分 e^x在0-1上积分

写一个用矩形法求定积分的通用公式 分别求 sinx在0-1上积分 cosx在0-1上积分 e^x在0-1上积分

时间:2021-06-14 16:50:39

相关推荐

写一个用矩形法求定积分的通用公式 分别求 sinx在0-1上积分 cosx在0-1上积分 e^x在0-1上积分

写一个用矩形法求定积分的通用公式,分别求 sinx在0-1上积分,cosx在0-1上积分,e^x在0-1上积分

#include <stdio.h>#include <stdlib.h>#include <math.h>double a[1001];void split(){for (int i = 0; i < 1001; i++){a[i] = (1.0 / 1000)*i;}}void cal_cos(){double ret = 0.0;for (int i = 0; i < 1000; i++){double avg = (a[i] + a[i + 1]) / 2.0;ret += (cos(avg)*(1.0 / 1000));}printf("%lf\n", ret);}void cal_e(){double ret = 0.0;for (int i = 0; i < 1000; i++){double avg = (a[i] + a[i + 1]) / 2.0;ret += (exp(avg)*(1.0 / 1000));}printf("%lf\n", ret);}void cal_sin(){double ret = 0.0;for (int i = 0; i < 1000; i++){double avg = (a[i] + a[i + 1]) / 2.0;ret += (sin(avg)*(1.0/1000));}printf("%lf\n", ret);}int main(){split();cal_sin();cal_cos();cal_e();system("pause");return 0;}

答案

写一个用矩形法求定积分的通用公式,分别求 sinx在0-1上积分,cosx在0-1上积分,e^x在0-1上积分

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。