根据Romberg算法计算定积分,和变步长的Simpson算法的输入都一样.算法基本分析:输入a,b(积分上下限),n为积分区间等分数,eps为计算精度,我这里1e-7,代表0乘以10的负7次方.本题目取的例子为数值书137面的例子2,f(x)= sin(x)/x,下面给出代码:
/********************************************
> File Name: Dragon.c
> Author:chendiyang
> School:WUST_CST_1501班
> Myblog:www.chendsir.com
> Mail:1441353519@qq.com
> Created Time: 2017年05月6日 星期六 12时33分10秒
************************************************************************/
#include <stdio.h>
#include <math.h>
#define N 20
#define MAX 10 //数组存的最大行数
#define a 0.0000001 //积分下限
#define b 1.0 //积分上限
#define eps 1e-7 //精度
double f(double x)//所求积分公式
{
return sin(x) / x;
}
double computeT(double aa, double bb, long int n)//复化梯形公式
{
int i;
double sum, h = (bb - aa) / n;
for (i = 1; i < n; i++)
sum &